summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2024-01-26 12:45:07 +0100
committerGitHub <noreply@github.com>2024-01-26 12:45:07 +0100
commit305757aec19c9d5111e4d76095ae0acd66163e4b (patch)
tree04aa017e66c06b3b19cb466ed4e1d73cd871523d /django/db
parent3f6d939c62efd967f548c27a265748cc2cc47ca5 (diff)
Applied Black's 2024 stable style.
https://github.com/psf/black/releases/tag/24.1.0
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/base/schema.py16
-rw-r--r--django/db/backends/ddl_references.py1
-rw-r--r--django/db/backends/mysql/base.py1
-rw-r--r--django/db/backends/oracle/base.py1
-rw-r--r--django/db/backends/oracle/creation.py18
-rw-r--r--django/db/backends/postgresql/base.py8
-rw-r--r--django/db/backends/postgresql/schema.py6
-rw-r--r--django/db/backends/sqlite3/_functions.py1
-rw-r--r--django/db/backends/sqlite3/base.py1
-rw-r--r--django/db/migrations/autodetector.py17
-rw-r--r--django/db/migrations/loader.py10
-rw-r--r--django/db/migrations/operations/models.py10
-rw-r--r--django/db/migrations/state.py10
-rw-r--r--django/db/models/aggregates.py1
-rw-r--r--django/db/models/base.py8
-rw-r--r--django/db/models/constants.py1
-rw-r--r--django/db/models/expressions.py42
-rw-r--r--django/db/models/fields/related_descriptors.py1
-rw-r--r--django/db/models/fields/reverse_related.py1
-rw-r--r--django/db/models/functions/comparison.py1
-rw-r--r--django/db/models/functions/datetime.py16
-rw-r--r--django/db/models/functions/math.py8
-rw-r--r--django/db/models/functions/mixins.py8
-rw-r--r--django/db/models/functions/text.py8
-rw-r--r--django/db/models/indexes.py8
-rw-r--r--django/db/models/lookups.py8
-rw-r--r--django/db/models/query.py20
-rw-r--r--django/db/models/query_utils.py1
-rw-r--r--django/db/models/sql/compiler.py6
-rw-r--r--django/db/models/sql/datastructures.py1
-rw-r--r--django/db/models/sql/query.py1
-rw-r--r--django/db/models/sql/where.py1
32 files changed, 139 insertions, 102 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py
index f01abf46b0..242083b850 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -724,9 +724,9 @@ class BaseDatabaseSchemaEditor:
namespace, _ = split_identifier(model._meta.db_table)
definition += " " + self.sql_create_column_inline_fk % {
"name": self._fk_constraint_name(model, field, constraint_suffix),
- "namespace": "%s." % self.quote_name(namespace)
- if namespace
- else "",
+ "namespace": (
+ "%s." % self.quote_name(namespace) if namespace else ""
+ ),
"column": self.quote_name(field.column),
"to_table": self.quote_name(to_table),
"to_column": self.quote_name(to_column),
@@ -1919,11 +1919,13 @@ class BaseDatabaseSchemaEditor:
"""Return all constraint names matching the columns and conditions."""
if column_names is not None:
column_names = [
- self.connection.introspection.identifier_converter(
- truncate_name(name, self.connection.ops.max_name_length())
+ (
+ self.connection.introspection.identifier_converter(
+ truncate_name(name, self.connection.ops.max_name_length())
+ )
+ if self.connection.features.truncates_names
+ else self.connection.introspection.identifier_converter(name)
)
- if self.connection.features.truncates_names
- else self.connection.introspection.identifier_converter(name)
for name in column_names
]
with self.connection.cursor() as cursor:
diff --git a/django/db/backends/ddl_references.py b/django/db/backends/ddl_references.py
index 412d07a993..75787ef8ab 100644
--- a/django/db/backends/ddl_references.py
+++ b/django/db/backends/ddl_references.py
@@ -2,6 +2,7 @@
Helpers to manipulate deferred DDL statements that might need to be adjusted or
discarded within when executing a migration.
"""
+
from copy import deepcopy
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index f36139881d..b8d2d09c94 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -3,6 +3,7 @@ MySQL database backend for Django.
Requires mysqlclient: https://pypi.org/project/mysqlclient/
"""
+
from django.core.exceptions import ImproperlyConfigured
from django.db import IntegrityError
from django.db.backends import utils as backend_utils
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 2d91468d25..f626c4d2d4 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -3,6 +3,7 @@ Oracle database backend for Django.
Requires oracledb: https://oracle.github.io/python-oracledb/
"""
+
import datetime
import decimal
import os
diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py
index df773bff8c..b0a5177728 100644
--- a/django/db/backends/oracle/creation.py
+++ b/django/db/backends/oracle/creation.py
@@ -133,20 +133,20 @@ class DatabaseCreation(BaseDatabaseCreation):
credentials in the SAVED_USER/SAVED_PASSWORD key in the settings dict.
"""
real_settings = settings.DATABASES[self.connection.alias]
- real_settings["SAVED_USER"] = self.connection.settings_dict[
- "SAVED_USER"
- ] = self.connection.settings_dict["USER"]
+ real_settings["SAVED_USER"] = self.connection.settings_dict["SAVED_USER"] = (
+ self.connection.settings_dict["USER"]
+ )
real_settings["SAVED_PASSWORD"] = self.connection.settings_dict[
"SAVED_PASSWORD"
] = self.connection.settings_dict["PASSWORD"]
real_test_settings = real_settings["TEST"]
test_settings = self.connection.settings_dict["TEST"]
- real_test_settings["USER"] = real_settings["USER"] = test_settings[
- "USER"
- ] = self.connection.settings_dict["USER"] = parameters["user"]
- real_settings["PASSWORD"] = self.connection.settings_dict[
- "PASSWORD"
- ] = parameters["password"]
+ real_test_settings["USER"] = real_settings["USER"] = test_settings["USER"] = (
+ self.connection.settings_dict["USER"]
+ ) = parameters["user"]
+ real_settings["PASSWORD"] = self.connection.settings_dict["PASSWORD"] = (
+ parameters["password"]
+ )
def set_as_test_mirror(self, primary_settings_dict):
"""
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index cba89e0cc7..8349d8f310 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -226,9 +226,11 @@ class DatabaseWrapper(BaseDatabaseWrapper):
server_side_binding = conn_params.pop("server_side_binding", None)
conn_params.setdefault(
"cursor_factory",
- ServerBindingCursor
- if is_psycopg3 and server_side_binding is True
- else Cursor,
+ (
+ ServerBindingCursor
+ if is_psycopg3 and server_side_binding is True
+ else Cursor
+ ),
)
if settings_dict["USER"]:
conn_params["user"] = settings_dict["USER"]
diff --git a/django/db/backends/postgresql/schema.py b/django/db/backends/postgresql/schema.py
index 5dc93a27d0..842830be30 100644
--- a/django/db/backends/postgresql/schema.py
+++ b/django/db/backends/postgresql/schema.py
@@ -267,9 +267,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
% {
"column": self.quote_name(new_field.column),
"type": new_type,
- "collation": " " + self._collate_sql(new_collation)
- if new_collation
- else "",
+ "collation": (
+ " " + self._collate_sql(new_collation) if new_collation else ""
+ ),
},
[],
)
diff --git a/django/db/backends/sqlite3/_functions.py b/django/db/backends/sqlite3/_functions.py
index 7e86950f7d..0171b60f38 100644
--- a/django/db/backends/sqlite3/_functions.py
+++ b/django/db/backends/sqlite3/_functions.py
@@ -1,6 +1,7 @@
"""
Implementations of SQL functions for SQLite.
"""
+
import functools
import random
import statistics
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 08de0bad5a..10a296c992 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -1,6 +1,7 @@
"""
SQLite backend for the sqlite3 module in the standard library.
"""
+
import datetime
import decimal
import warnings
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index 6b01403d18..f000d9fcaa 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -620,11 +620,12 @@ class MigrationAutodetector:
rem_model_state.app_label,
rem_model_state.name_lower,
)
- self.renamed_models_rel[
- renamed_models_rel_key
- ] = "%s.%s" % (
- model_state.app_label,
- model_state.name_lower,
+ self.renamed_models_rel[renamed_models_rel_key] = (
+ "%s.%s"
+ % (
+ model_state.app_label,
+ model_state.name_lower,
+ )
)
self.old_model_keys.remove((rem_app_label, rem_model_name))
self.old_model_keys.add((app_label, model_name))
@@ -1058,9 +1059,9 @@ class MigrationAutodetector:
(rem_app_label, rem_model_name, rem_field_name)
)
old_field_keys.add((app_label, model_name, field_name))
- self.renamed_fields[
- app_label, model_name, field_name
- ] = rem_field_name
+ self.renamed_fields[app_label, model_name, field_name] = (
+ rem_field_name
+ )
break
def generate_renamed_fields(self):
diff --git a/django/db/migrations/loader.py b/django/db/migrations/loader.py
index 81dcd06e04..50445f3101 100644
--- a/django/db/migrations/loader.py
+++ b/django/db/migrations/loader.py
@@ -131,11 +131,11 @@ class MigrationLoader:
"Migration %s in app %s has no Migration class"
% (migration_name, app_config.label)
)
- self.disk_migrations[
- app_config.label, migration_name
- ] = migration_module.Migration(
- migration_name,
- app_config.label,
+ self.disk_migrations[app_config.label, migration_name] = (
+ migration_module.Migration(
+ migration_name,
+ app_config.label,
+ )
)
def get_migration(self, app_label, name_prefix):
diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
index b24a8f6557..38c68f3ff3 100644
--- a/django/db/migrations/operations/models.py
+++ b/django/db/migrations/operations/models.py
@@ -56,11 +56,11 @@ class CreateModel(ModelOperation):
_check_for_duplicates(
"bases",
(
- base._meta.label_lower
- if hasattr(base, "_meta")
- else base.lower()
- if isinstance(base, str)
- else base
+ (
+ base._meta.label_lower
+ if hasattr(base, "_meta")
+ else base.lower() if isinstance(base, str) else base
+ )
for base in self.bases
),
)
diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
index 5ffd7fc07a..42a2c80a5e 100644
--- a/django/db/migrations/state.py
+++ b/django/db/migrations/state.py
@@ -524,11 +524,11 @@ class ProjectState:
if model_state.options.get("proxy"):
proxy_models[model_key] = model_state
# Find a concrete model for the proxy.
- concrete_models_mapping[
- model_key
- ] = self._find_concrete_model_from_proxy(
- proxy_models,
- model_state,
+ concrete_models_mapping[model_key] = (
+ self._find_concrete_model_from_proxy(
+ proxy_models,
+ model_state,
+ )
)
else:
concrete_models_mapping[model_key] = model_key
diff --git a/django/db/models/aggregates.py b/django/db/models/aggregates.py
index a778cd413b..0cbffacd1b 100644
--- a/django/db/models/aggregates.py
+++ b/django/db/models/aggregates.py
@@ -1,6 +1,7 @@
"""
Classes to represent the definitions of aggregate functions.
"""
+
from django.core.exceptions import FieldError, FullResultSet
from django.db.models.expressions import Case, Func, Star, Value, When
from django.db.models.fields import IntegerField
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 61925f63ea..c1f78d0632 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -2265,9 +2265,11 @@ class Model(AltersData, metaclass=ModelBase):
opts = cls._meta
valid_fields = set(
chain.from_iterable(
- (f.name, f.attname)
- if not (f.auto_created and not f.concrete)
- else (f.field.related_query_name(),)
+ (
+ (f.name, f.attname)
+ if not (f.auto_created and not f.concrete)
+ else (f.field.related_query_name(),)
+ )
for f in chain(opts.fields, opts.related_objects)
)
)
diff --git a/django/db/models/constants.py b/django/db/models/constants.py
index a0c99c95fc..cec1b9b90f 100644
--- a/django/db/models/constants.py
+++ b/django/db/models/constants.py
@@ -1,6 +1,7 @@
"""
Constants used across the ORM in general.
"""
+
from enum import Enum
# Separator used to split filter strings apart.
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index f25ad1af12..6d329ae85d 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -204,9 +204,11 @@ class BaseExpression:
def _parse_expressions(self, *expressions):
return [
- arg
- if hasattr(arg, "resolve_expression")
- else (F(arg) if isinstance(arg, str) else Value(arg))
+ (
+ arg
+ if hasattr(arg, "resolve_expression")
+ else (F(arg) if isinstance(arg, str) else Value(arg))
+ )
for arg in expressions
]
@@ -285,9 +287,11 @@ class BaseExpression:
c.is_summary = summarize
c.set_source_expressions(
[
- expr.resolve_expression(query, allow_joins, reuse, summarize)
- if expr
- else None
+ (
+ expr.resolve_expression(query, allow_joins, reuse, summarize)
+ if expr
+ else None
+ )
for expr in c.get_source_expressions()
]
)
@@ -366,22 +370,16 @@ class BaseExpression:
field = self.output_field
internal_type = field.get_internal_type()
if internal_type == "FloatField":
- return (
- lambda value, expression, connection: None
- if value is None
- else float(value)
+ return lambda value, expression, connection: (
+ None if value is None else float(value)
)
elif internal_type.endswith("IntegerField"):
- return (
- lambda value, expression, connection: None
- if value is None
- else int(value)
+ return lambda value, expression, connection: (
+ None if value is None else int(value)
)
elif internal_type == "DecimalField":
- return (
- lambda value, expression, connection: None
- if value is None
- else Decimal(value)
+ return lambda value, expression, connection: (
+ None if value is None else Decimal(value)
)
return self._convert_value_noop
@@ -432,9 +430,11 @@ class BaseExpression:
clone = self.copy()
clone.set_source_expressions(
[
- F(f"{prefix}{expr.name}")
- if isinstance(expr, F)
- else expr.prefix_references(prefix)
+ (
+ F(f"{prefix}{expr.name}")
+ if isinstance(expr, F)
+ else expr.prefix_references(prefix)
+ )
for expr in self.get_source_expressions()
]
)
diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py
index f5a81ab49c..62ddfc60b3 100644
--- a/django/db/models/fields/related_descriptors.py
+++ b/django/db/models/fields/related_descriptors.py
@@ -62,6 +62,7 @@ and two directions (forward and reverse) for a total of six combinations.
If you're looking for ``ForwardManyToManyDescriptor`` or
``ReverseManyToManyDescriptor``, use ``ManyToManyDescriptor`` instead.
"""
+
import warnings
from asgiref.sync import sync_to_async
diff --git a/django/db/models/fields/reverse_related.py b/django/db/models/fields/reverse_related.py
index c74e92ba89..144cce6142 100644
--- a/django/db/models/fields/reverse_related.py
+++ b/django/db/models/fields/reverse_related.py
@@ -8,6 +8,7 @@ in the ``remote_field`` attribute of the field.
They also act as reverse fields for the purposes of the Meta API because
they're the closest concept currently available.
"""
+
import warnings
from django.core import exceptions
diff --git a/django/db/models/functions/comparison.py b/django/db/models/functions/comparison.py
index ae41f1da95..6db81d6f46 100644
--- a/django/db/models/functions/comparison.py
+++ b/django/db/models/functions/comparison.py
@@ -1,4 +1,5 @@
"""Database functions that do comparisons or type conversions."""
+
from django.db import NotSupportedError
from django.db.models.expressions import Func, Value
from django.db.models.fields import TextField
diff --git a/django/db/models/functions/datetime.py b/django/db/models/functions/datetime.py
index fca211e065..9937e79f6f 100644
--- a/django/db/models/functions/datetime.py
+++ b/django/db/models/functions/datetime.py
@@ -318,9 +318,11 @@ class TruncBase(TimezoneMixin, Transform):
"Cannot truncate DateField '%s' to %s."
% (
field.name,
- output_field.__class__.__name__
- if has_explicit_output_field
- else "DateTimeField",
+ (
+ output_field.__class__.__name__
+ if has_explicit_output_field
+ else "DateTimeField"
+ ),
)
)
elif isinstance(field, TimeField) and (
@@ -331,9 +333,11 @@ class TruncBase(TimezoneMixin, Transform):
"Cannot truncate TimeField '%s' to %s."
% (
field.name,
- output_field.__class__.__name__
- if has_explicit_output_field
- else "DateTimeField",
+ (
+ output_field.__class__.__name__
+ if has_explicit_output_field
+ else "DateTimeField"
+ ),
)
)
return copy
diff --git a/django/db/models/functions/math.py b/django/db/models/functions/math.py
index 460143ba5a..5fa4654a84 100644
--- a/django/db/models/functions/math.py
+++ b/django/db/models/functions/math.py
@@ -47,9 +47,11 @@ class ATan2(NumericOutputFieldMixin, Func):
clone = self.copy()
clone.set_source_expressions(
[
- Cast(expression, FloatField())
- if isinstance(expression.output_field, IntegerField)
- else expression
+ (
+ Cast(expression, FloatField())
+ if isinstance(expression.output_field, IntegerField)
+ else expression
+ )
for expression in self.get_source_expressions()[::-1]
]
)
diff --git a/django/db/models/functions/mixins.py b/django/db/models/functions/mixins.py
index 661eee1c13..0f6f0a2aa8 100644
--- a/django/db/models/functions/mixins.py
+++ b/django/db/models/functions/mixins.py
@@ -14,9 +14,11 @@ class FixDecimalInputMixin:
clone = self.copy()
clone.set_source_expressions(
[
- Cast(expression, output_field)
- if isinstance(expression.output_field, FloatField)
- else expression
+ (
+ Cast(expression, output_field)
+ if isinstance(expression.output_field, FloatField)
+ else expression
+ )
for expression in self.get_source_expressions()
]
)
diff --git a/django/db/models/functions/text.py b/django/db/models/functions/text.py
index 392061880c..df826ffdb5 100644
--- a/django/db/models/functions/text.py
+++ b/django/db/models/functions/text.py
@@ -89,9 +89,11 @@ class ConcatPair(Func):
c = self.copy()
c.set_source_expressions(
[
- expression
- if isinstance(expression.output_field, (CharField, TextField))
- else Cast(expression, TextField())
+ (
+ expression
+ if isinstance(expression.output_field, (CharField, TextField))
+ else Cast(expression, TextField())
+ )
for expression in c.get_source_expressions()
]
)
diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py
index b5451f9e24..0ddfefec38 100644
--- a/django/db/models/indexes.py
+++ b/django/db/models/indexes.py
@@ -196,9 +196,11 @@ class Index:
"" if not self.fields else " fields=%s" % repr(self.fields),
"" if not self.expressions else " expressions=%s" % repr(self.expressions),
"" if not self.name else " name=%s" % repr(self.name),
- ""
- if self.db_tablespace is None
- else " db_tablespace=%s" % repr(self.db_tablespace),
+ (
+ ""
+ if self.db_tablespace is None
+ else " db_tablespace=%s" % repr(self.db_tablespace)
+ ),
"" if self.condition is None else " condition=%s" % self.condition,
"" if not self.include else " include=%s" % repr(self.include),
"" if not self.opclasses else " opclasses=%s" % repr(self.opclasses),
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index 4a6e2b3241..139875eed5 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -273,9 +273,11 @@ class FieldGetDbPrepValueMixin:
return (
"%s",
[
- v
- if hasattr(v, "as_sql")
- else get_db_prep_value(v, connection, prepared=True)
+ (
+ v
+ if hasattr(v, "as_sql")
+ else get_db_prep_value(v, connection, prepared=True)
+ )
for v in value
],
)
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 61d4002000..b9e2d1f7e5 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -109,9 +109,11 @@ class ModelIterable(BaseIterable):
related_objs,
operator.attrgetter(
*[
- field.attname
- if from_field == "self"
- else queryset.model._meta.get_field(from_field).attname
+ (
+ field.attname
+ if from_field == "self"
+ else queryset.model._meta.get_field(from_field).attname
+ )
for from_field in field.from_fields
]
),
@@ -1391,9 +1393,7 @@ class QuerySet(AltersData):
clone._iterable_class = (
NamedValuesListIterable
if named
- else FlatValuesListIterable
- if flat
- else ValuesListIterable
+ else FlatValuesListIterable if flat else ValuesListIterable
)
return clone
@@ -1659,9 +1659,11 @@ class QuerySet(AltersData):
if names is None:
names = set(
chain.from_iterable(
- (field.name, field.attname)
- if hasattr(field, "attname")
- else (field.name,)
+ (
+ (field.name, field.attname)
+ if hasattr(field, "attname")
+ else (field.name,)
+ )
for field in self.model._meta.get_fields()
)
)
diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py
index 4f3358eb8d..e1041b9653 100644
--- a/django/db/models/query_utils.py
+++ b/django/db/models/query_utils.py
@@ -5,6 +5,7 @@ Factored out from django.db.models.query to avoid making the main module very
large and/or so that they can be used by other modules without getting into
circular import difficulties.
"""
+
import functools
import inspect
import logging
diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
index 10338259d5..9a0d2eb4e7 100644
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -1224,9 +1224,9 @@ class SQLCompiler:
"field": f,
"reverse": False,
"local_setter": f.set_cached_value,
- "remote_setter": f.remote_field.set_cached_value
- if f.unique
- else lambda x, y: None,
+ "remote_setter": (
+ f.remote_field.set_cached_value if f.unique else lambda x, y: None
+ ),
"from_parent": False,
}
related_klass_infos.append(klass_info)
diff --git a/django/db/models/sql/datastructures.py b/django/db/models/sql/datastructures.py
index 5eaa8c25f6..7c0c14a46e 100644
--- a/django/db/models/sql/datastructures.py
+++ b/django/db/models/sql/datastructures.py
@@ -2,6 +2,7 @@
Useful auxiliary data structures for query construction. Not useful outside
the SQL domain.
"""
+
import warnings
from django.core.exceptions import FullResultSet
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index ce4fafb1e2..6e8813b5e7 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -6,6 +6,7 @@ themselves do not have to (and could be backed by things other than SQL
databases). The abstraction barrier only works one way: this module has to know
all about the internals of models in order to get the information it needs.
"""
+
import copy
import difflib
import functools
diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py
index 8423fcb528..0fded5cce3 100644
--- a/django/db/models/sql/where.py
+++ b/django/db/models/sql/where.py
@@ -1,6 +1,7 @@
"""
Code to manage the creation and SQL rendering of 'where' constraints.
"""
+
import operator
from functools import reduce