mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Refs #33476 -- Applied Black's 2023 stable style.
Black 23.1.0 is released which, as the first release of the year, introduces the 2023 stable style. This incorporates most of last year's preview style. https://github.com/psf/black/releases/tag/23.1.0
This commit is contained in:
committed by
Mariusz Felisiak
parent
8c660fb592
commit
097e3a70c1
@@ -4,7 +4,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
("contenttypes", "__first__"),
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.utils import timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("admin", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("admin", "0002_logentry_remove_auto_add"),
|
||||
]
|
||||
|
||||
@@ -982,7 +982,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
base_action_names = {name for _, name, _ in base_actions}
|
||||
|
||||
# Gather actions from the admin site first
|
||||
for (name, func) in self.admin_site.actions:
|
||||
for name, func in self.admin_site.actions:
|
||||
if name in base_action_names:
|
||||
continue
|
||||
description = self._get_action_description(func, name)
|
||||
@@ -1106,6 +1106,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||
Return a tuple containing a queryset to implement the search
|
||||
and a boolean indicating if the results may contain duplicates.
|
||||
"""
|
||||
|
||||
# Apply keyword searches.
|
||||
def construct_search(field_name):
|
||||
if field_name.startswith("^"):
|
||||
|
||||
@@ -17,7 +17,6 @@ class CSPMiddleware(MiddlewareMixin):
|
||||
|
||||
@modify_settings(MIDDLEWARE={"append": "django.contrib.admin.tests.CSPMiddleware"})
|
||||
class AdminSeleniumTestCase(SeleniumTestCase, StaticLiveServerTestCase):
|
||||
|
||||
available_apps = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
|
||||
@@ -148,7 +148,7 @@ class ViewIndexView(BaseAdminDocsView):
|
||||
view_functions = extract_views_from_urlpatterns(url_resolver.url_patterns)
|
||||
except ImproperlyConfigured:
|
||||
view_functions = []
|
||||
for (func, regex, namespace, name) in view_functions:
|
||||
for func, regex, namespace, name in view_functions:
|
||||
views.append(
|
||||
{
|
||||
"full_name": get_view_name(func),
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.utils import timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("contenttypes", "__first__"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0002_alter_permission_name_max_length"),
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0003_alter_user_email_max_length"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0004_alter_user_username_opts"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0005_alter_user_last_login_null"),
|
||||
("contenttypes", "0002_remove_content_type_name"),
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0006_require_contenttypes_0002"),
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0007_alter_validators_add_error_messages"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0008_alter_user_username_max_length"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0009_alter_user_last_name_max_length"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("auth", "0011_update_proxy_permissions"),
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
|
||||
@@ -13,7 +13,6 @@ def add_legacy_name(apps, schema_editor):
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("contenttypes", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("sites", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -54,7 +54,6 @@ class SDORelate(SpatialOperator):
|
||||
|
||||
|
||||
class OracleOperations(BaseSpatialOperations, DatabaseOperations):
|
||||
|
||||
name = "oracle"
|
||||
oracle = True
|
||||
disallowed_aggregates = (models.Collect, models.Extent3D, models.MakeLine)
|
||||
|
||||
@@ -20,7 +20,6 @@ from django.utils.encoding import force_bytes, force_str
|
||||
|
||||
|
||||
class GEOSGeometryBase(GEOSBase):
|
||||
|
||||
_GEOS_CLASSES = None
|
||||
|
||||
ptr_type = GEOM_PTR
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("sites", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -2,7 +2,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("redirects", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
|
||||
@@ -47,7 +47,6 @@ def index(
|
||||
content_type="application/xml",
|
||||
sitemap_url_name="django.contrib.sitemaps.views.sitemap",
|
||||
):
|
||||
|
||||
req_protocol = request.scheme
|
||||
req_site = get_current_site(request)
|
||||
|
||||
@@ -97,7 +96,6 @@ def sitemap(
|
||||
template_name="sitemap.xml",
|
||||
content_type="application/xml",
|
||||
):
|
||||
|
||||
req_protocol = request.scheme
|
||||
req_site = get_current_site(request)
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = []
|
||||
|
||||
operations = [
|
||||
|
||||
@@ -3,7 +3,6 @@ from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("sites", "0001_initial"),
|
||||
]
|
||||
|
||||
@@ -77,7 +77,6 @@ class SiteManager(models.Manager):
|
||||
|
||||
|
||||
class Site(models.Model):
|
||||
|
||||
domain = models.CharField(
|
||||
_("domain name"),
|
||||
max_length=100,
|
||||
|
||||
1
django/core/cache/backends/db.py
vendored
1
django/core/cache/backends/db.py
vendored
@@ -40,7 +40,6 @@ class BaseDatabaseCache(BaseCache):
|
||||
|
||||
|
||||
class DatabaseCache(BaseDatabaseCache):
|
||||
|
||||
# This class uses cursors provided by the database connection. This means
|
||||
# it reads expiration values as aware or naive datetimes, depending on the
|
||||
# value of USE_TZ and whether the database supports time zones. The ORM's
|
||||
|
||||
@@ -193,7 +193,7 @@ class Command(BaseCommand):
|
||||
# There is no need to sort dependencies when natural foreign
|
||||
# keys are not used.
|
||||
models = []
|
||||
for (app_config, model_list) in app_list.items():
|
||||
for app_config, model_list in app_list.items():
|
||||
if model_list is None:
|
||||
models.extend(app_config.get_models())
|
||||
else:
|
||||
|
||||
@@ -60,7 +60,6 @@ class Command(BaseCommand):
|
||||
)
|
||||
|
||||
def handle(self, **options):
|
||||
|
||||
self.verbosity = options["verbosity"]
|
||||
self.interactive = options["interactive"]
|
||||
app_label = options["app_label"]
|
||||
|
||||
@@ -158,7 +158,6 @@ class TemplateCommand(BaseCommand):
|
||||
prefix_length = len(template_dir) + 1
|
||||
|
||||
for root, dirs, files in os.walk(template_dir):
|
||||
|
||||
path_rest = root[prefix_length:]
|
||||
relative_dir = path_rest.replace(base_name, name)
|
||||
if relative_dir:
|
||||
|
||||
@@ -128,8 +128,7 @@ def Deserializer(
|
||||
field_names = field_names_cache[Model]
|
||||
|
||||
# Handle each field
|
||||
for (field_name, field_value) in d["fields"].items():
|
||||
|
||||
for field_name, field_value in d["fields"].items():
|
||||
if ignorenonexistent and field_name not in field_names:
|
||||
# skip fields no longer on model
|
||||
continue
|
||||
|
||||
@@ -116,6 +116,7 @@ class BaseDatabaseCreation:
|
||||
Designed only for test runner usage; will not handle large
|
||||
amounts of data.
|
||||
"""
|
||||
|
||||
# Iteratively return every object for all models to serialize.
|
||||
def get_objects():
|
||||
from django.db.migrations.loader import MigrationLoader
|
||||
|
||||
@@ -269,6 +269,7 @@ class BaseDatabaseOperations:
|
||||
exists for database backends to provide a better implementation
|
||||
according to their own quoting schemes.
|
||||
"""
|
||||
|
||||
# Convert params to contain string values.
|
||||
def to_string(s):
|
||||
return force_str(s, strings_only=True, errors="replace")
|
||||
|
||||
@@ -4,7 +4,6 @@ from django.db.models.constants import LOOKUP_SEP
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
sql_rename_table = "RENAME TABLE %(old_table)s TO %(new_table)s"
|
||||
|
||||
sql_alter_column_null = "MODIFY %(column)s %(type)s NULL"
|
||||
|
||||
@@ -11,7 +11,6 @@ from django.utils.duration import duration_iso_string
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
sql_create_column = "ALTER TABLE %(table)s ADD %(column)s %(definition)s"
|
||||
sql_alter_column_type = "MODIFY %(column)s %(type)s%(collation)s"
|
||||
sql_alter_column_null = "MODIFY %(column)s NULL"
|
||||
|
||||
@@ -476,7 +476,6 @@ if is_psycopg3:
|
||||
return self.cursor.copy(statement)
|
||||
|
||||
else:
|
||||
|
||||
Cursor = psycopg2.extensions.cursor
|
||||
|
||||
class CursorDebugWrapper(BaseCursorDebugWrapper):
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.db.backends.utils import strip_quotes
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
# Setting all constraints to IMMEDIATE to allow changing data in the same
|
||||
# transaction.
|
||||
sql_update_with_default = (
|
||||
|
||||
@@ -11,7 +11,6 @@ from django.db.transaction import atomic
|
||||
|
||||
|
||||
class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
|
||||
sql_delete_table = "DROP TABLE %(table)s"
|
||||
sql_create_fk = None
|
||||
sql_create_inline_fk = (
|
||||
@@ -191,6 +190,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||
4. Rename the "new__app_model" table to "app_model"
|
||||
5. Restore any index of the previous "app_model" table.
|
||||
"""
|
||||
|
||||
# Self-referential fields must be recreated rather than copied from
|
||||
# the old model to ensure their remote_field.field_name doesn't refer
|
||||
# to an altered field.
|
||||
|
||||
@@ -95,7 +95,6 @@ class CursorWrapper:
|
||||
|
||||
|
||||
class CursorDebugWrapper(CursorWrapper):
|
||||
|
||||
# XXX callproc isn't instrumented at this time.
|
||||
|
||||
def execute(self, sql, params=None):
|
||||
|
||||
@@ -400,7 +400,7 @@ class RenameModel(ModelOperation):
|
||||
fields = zip(
|
||||
old_model._meta.local_many_to_many, new_model._meta.local_many_to_many
|
||||
)
|
||||
for (old_field, new_field) in fields:
|
||||
for old_field, new_field in fields:
|
||||
# Skip self-referential fields as these are renamed above.
|
||||
if (
|
||||
new_field.model == new_field.related_model
|
||||
@@ -505,7 +505,7 @@ class AlterModelTable(ModelOptionOperation):
|
||||
new_model._meta.db_table,
|
||||
)
|
||||
# Rename M2M fields whose name is based on this model's db_table
|
||||
for (old_field, new_field) in zip(
|
||||
for old_field, new_field in zip(
|
||||
old_model._meta.local_many_to_many, new_model._meta.local_many_to_many
|
||||
):
|
||||
if new_field.remote_field.through._meta.auto_created:
|
||||
|
||||
@@ -1106,7 +1106,6 @@ class Star(Expression):
|
||||
|
||||
|
||||
class Col(Expression):
|
||||
|
||||
contains_column_references = True
|
||||
possibly_multivalued = False
|
||||
|
||||
|
||||
@@ -222,7 +222,6 @@ class FileDescriptor(DeferredAttribute):
|
||||
|
||||
|
||||
class FileField(Field):
|
||||
|
||||
# The class to wrap instance attributes in. Accessing the file object off
|
||||
# the instance will always return an instance of attr_class.
|
||||
attr_class = FieldFile
|
||||
|
||||
@@ -344,7 +344,6 @@ class RelatedField(FieldCacheMixin, Field):
|
||||
return None
|
||||
|
||||
def contribute_to_class(self, cls, name, private_only=False, **kwargs):
|
||||
|
||||
super().contribute_to_class(cls, name, private_only=private_only, **kwargs)
|
||||
|
||||
self.opts = cls._meta
|
||||
@@ -541,7 +540,6 @@ class ForeignObject(RelatedField):
|
||||
swappable=True,
|
||||
**kwargs,
|
||||
):
|
||||
|
||||
if rel is None:
|
||||
rel = self.rel_class(
|
||||
self,
|
||||
@@ -1616,7 +1614,6 @@ class ManyToManyField(RelatedField):
|
||||
(source_field_name, source),
|
||||
(target_field_name, target),
|
||||
):
|
||||
|
||||
possible_field_names = []
|
||||
for f in through._meta.fields:
|
||||
if (
|
||||
|
||||
@@ -528,6 +528,7 @@ class Options:
|
||||
combined with filtering of field properties is the public API for
|
||||
obtaining this field list.
|
||||
"""
|
||||
|
||||
# For legacy reasons, the fields property should only contain forward
|
||||
# fields that are not private or with a m2m cardinality. Therefore we
|
||||
# pass these three filters as filters to the generator.
|
||||
|
||||
@@ -2110,7 +2110,7 @@ class RawQuerySet:
|
||||
"""
|
||||
columns = self.query.get_columns()
|
||||
# Adjust any column names which don't match field names
|
||||
for (query_name, model_name) in self.translations.items():
|
||||
for query_name, model_name in self.translations.items():
|
||||
# Ignore translations for nonexistent column names
|
||||
try:
|
||||
index = columns.index(query_name)
|
||||
|
||||
@@ -482,7 +482,6 @@ class ClearableFileInput(FileInput):
|
||||
if not self.is_required and CheckboxInput().value_from_datadict(
|
||||
data, files, self.clear_checkbox_name(name)
|
||||
):
|
||||
|
||||
if upload:
|
||||
# If the user contradicts themselves (uploads a new file AND
|
||||
# checks the "clear" checkbox), we return a unique marker
|
||||
|
||||
@@ -5,7 +5,6 @@ from django.utils.functional import cached_property
|
||||
|
||||
|
||||
class BaseEngine:
|
||||
|
||||
# Core methods: engines have to provide their own implementation
|
||||
# (except for from_string which is optional).
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ from .base import BaseEngine
|
||||
|
||||
|
||||
class DjangoTemplates(BaseEngine):
|
||||
|
||||
app_dirname = "templates"
|
||||
|
||||
def __init__(self, params):
|
||||
|
||||
@@ -9,7 +9,6 @@ from .utils import csrf_input_lazy, csrf_token_lazy
|
||||
|
||||
|
||||
class TemplateStrings(BaseEngine):
|
||||
|
||||
app_dirname = "template_strings"
|
||||
|
||||
def __init__(self, params):
|
||||
|
||||
@@ -12,7 +12,6 @@ from .utils import csrf_input_lazy, csrf_token_lazy
|
||||
|
||||
|
||||
class Jinja2(BaseEngine):
|
||||
|
||||
app_dirname = "jinja2"
|
||||
|
||||
def __init__(self, params):
|
||||
|
||||
@@ -309,7 +309,6 @@ class IfNode(Node):
|
||||
|
||||
def render(self, context):
|
||||
for condition, nodelist in self.conditions_nodelists:
|
||||
|
||||
if condition is not None: # if / elif clause
|
||||
try:
|
||||
match = condition.eval(context)
|
||||
|
||||
@@ -270,7 +270,7 @@ def encode_multipart(boundary, data):
|
||||
# Each bit of the multipart form data could be either a form value or a
|
||||
# file, or a *list* of form values and/or files. Remember that HTTP field
|
||||
# names can be duplicated!
|
||||
for (key, value) in data.items():
|
||||
for key, value in data.items():
|
||||
if value is None:
|
||||
raise TypeError(
|
||||
"Cannot encode None for key '%s' as POST data. Did you mean "
|
||||
|
||||
@@ -657,7 +657,6 @@ class DiscoverRunner:
|
||||
logger=None,
|
||||
**kwargs,
|
||||
):
|
||||
|
||||
self.pattern = pattern
|
||||
self.top_level = top_level
|
||||
self.verbosity = verbosity
|
||||
|
||||
@@ -166,7 +166,6 @@ class _DatabaseFailure:
|
||||
|
||||
|
||||
class SimpleTestCase(unittest.TestCase):
|
||||
|
||||
# The class we'll use for the test client self.client.
|
||||
# Can be overridden in derived classes.
|
||||
client_class = Client
|
||||
@@ -652,7 +651,6 @@ class SimpleTestCase(unittest.TestCase):
|
||||
)
|
||||
|
||||
def _get_template_used(self, response, template_name, msg_prefix, method_name):
|
||||
|
||||
if response is None and template_name is None:
|
||||
raise TypeError("response and/or template_name argument must be provided")
|
||||
|
||||
@@ -983,7 +981,6 @@ class SimpleTestCase(unittest.TestCase):
|
||||
|
||||
|
||||
class TransactionTestCase(SimpleTestCase):
|
||||
|
||||
# Subclasses can ask for resetting of auto increment sequence before each
|
||||
# test case
|
||||
reset_sequences = False
|
||||
|
||||
@@ -78,7 +78,7 @@ def patch_cache_control(response, **kwargs):
|
||||
elif "public" in cc and "private" in kwargs:
|
||||
del cc["public"]
|
||||
|
||||
for (k, v) in kwargs.items():
|
||||
for k, v in kwargs.items():
|
||||
directive = k.replace("_", "-")
|
||||
if directive == "no-cache":
|
||||
# no-cache supports multiple field names.
|
||||
|
||||
@@ -57,6 +57,7 @@ def method_decorator(decorator, name=""):
|
||||
"""
|
||||
Convert a function decorator into a method decorator
|
||||
"""
|
||||
|
||||
# 'obj' can be a class or a function. If 'obj' is a function at the time it
|
||||
# is passed to _dec, it will eventually be a method of the class it is
|
||||
# defined on. If 'obj' is a class, the 'name' is required to be the name
|
||||
|
||||
@@ -41,7 +41,6 @@ def format(
|
||||
if isinstance(number, float) and "e" in str(number).lower():
|
||||
number = Decimal(str(number))
|
||||
if isinstance(number, Decimal):
|
||||
|
||||
if decimal_pos is not None:
|
||||
# If the provided number is too small to affect any of the visible
|
||||
# decimal places, consider it equal to '0'.
|
||||
|
||||
@@ -6,6 +6,7 @@ def no_append_slash(view_func):
|
||||
Mark a view function as excluded from CommonMiddleware's APPEND_SLASH
|
||||
redirection.
|
||||
"""
|
||||
|
||||
# view_func.should_append_slash = False would also work, but decorators are
|
||||
# nicer if they don't have side effects, so return a new function.
|
||||
@wraps(view_func)
|
||||
|
||||
@@ -48,6 +48,7 @@ uses the csrf_token template tag, or the CsrfViewMiddleware is used.
|
||||
|
||||
def csrf_exempt(view_func):
|
||||
"""Mark a view function as being exempt from the CSRF view protection."""
|
||||
|
||||
# view_func.csrf_exempt = True would also work, but decorators are nicer
|
||||
# if they don't have side effects, so return a new function.
|
||||
@wraps(view_func)
|
||||
|
||||
Reference in New Issue
Block a user