summaryrefslogtreecommitdiff
path: root/django/db
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-04-03 20:37:32 -0400
committerTim Graham <timograham@gmail.com>2016-04-04 17:14:26 -0400
commit2cd2d188516475ddf256e6267cd82c495fb5c430 (patch)
tree1a7c3c167c1576923c7c4f5544495face5bd7327 /django/db
parentd356bb653f4d90ae9809e5a051791ded39010c38 (diff)
Fixed W503 flake8 warnings.
Diffstat (limited to 'django/db')
-rw-r--r--django/db/backends/base/base.py14
-rw-r--r--django/db/backends/mysql/introspection.py20
-rw-r--r--django/db/backends/mysql/validation.py5
-rw-r--r--django/db/backends/oracle/base.py5
-rw-r--r--django/db/backends/oracle/compiler.py3
-rw-r--r--django/db/backends/postgresql/introspection.py10
-rw-r--r--django/db/migrations/autodetector.py12
-rw-r--r--django/db/migrations/graph.py6
-rw-r--r--django/db/models/base.py14
-rw-r--r--django/db/models/deletion.py6
-rw-r--r--django/db/models/expressions.py4
-rw-r--r--django/db/models/fields/__init__.py3
-rw-r--r--django/db/models/fields/files.py4
-rw-r--r--django/db/models/lookups.py4
-rw-r--r--django/db/models/options.py6
-rw-r--r--django/db/models/query.py4
-rw-r--r--django/db/models/sql/query.py14
17 files changed, 66 insertions, 68 deletions
diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py
index 0356ab54cc..6893a76bee 100644
--- a/django/db/backends/base/base.py
+++ b/django/db/backends/base/base.py
@@ -381,9 +381,8 @@ class BaseDatabaseWrapper(object):
self.ensure_connection()
start_transaction_under_autocommit = (
- force_begin_transaction_with_broken_autocommit
- and not autocommit
- and self.features.autocommits_when_autocommit_is_off
+ force_begin_transaction_with_broken_autocommit and not autocommit and
+ self.features.autocommits_when_autocommit_is_off
)
if start_transaction_under_autocommit:
@@ -514,13 +513,14 @@ class BaseDatabaseWrapper(object):
authorized to be shared between threads (via the `allow_thread_sharing`
property). Raises an exception if the validation fails.
"""
- if not (self.allow_thread_sharing
- or self._thread_ident == thread.get_ident()):
- raise DatabaseError("DatabaseWrapper objects created in a "
+ if not (self.allow_thread_sharing or self._thread_ident == thread.get_ident()):
+ raise DatabaseError(
+ "DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
- % (self.alias, self._thread_ident, thread.get_ident()))
+ % (self.alias, self._thread_ident, thread.get_ident())
+ )
# ##### Miscellaneous #####
diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py
index 6b324b738a..4ac8864ba6 100644
--- a/django/db/backends/mysql/introspection.py
+++ b/django/db/backends/mysql/introspection.py
@@ -79,14 +79,18 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
for line in cursor.description:
col_name = force_text(line[0])
fields.append(
- FieldInfo(*((col_name,)
- + line[1:3]
- + (to_int(field_info[col_name].max_len) or line[3],
- to_int(field_info[col_name].num_prec) or line[4],
- to_int(field_info[col_name].num_scale) or line[5])
- + (line[6],)
- + (field_info[col_name].extra,)
- + (field_info[col_name].column_default,)))
+ FieldInfo(*(
+ (col_name,) +
+ line[1:3] +
+ (
+ to_int(field_info[col_name].max_len) or line[3],
+ to_int(field_info[col_name].num_prec) or line[4],
+ to_int(field_info[col_name].num_scale) or line[5],
+ line[6],
+ field_info[col_name].extra,
+ field_info[col_name].column_default,
+ )
+ ))
)
return fields
diff --git a/django/db/backends/mysql/validation.py b/django/db/backends/mysql/validation.py
index 83381e0f79..2e3bb0279b 100644
--- a/django/db/backends/mysql/validation.py
+++ b/django/db/backends/mysql/validation.py
@@ -21,9 +21,8 @@ class DatabaseValidation(BaseDatabaseValidation):
if field_type is None:
return errors
- if (field_type.startswith('varchar') # Look for CharFields...
- and field.unique # ... that are unique
- and (field.max_length is None or int(field.max_length) > 255)):
+ if (field_type.startswith('varchar') and field.unique and
+ (field.max_length is None or int(field.max_length) > 255)):
errors.append(
checks.Error(
'MySQL does not allow unique CharFields to have a max_length > 255.',
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index ef93300737..43b435fed4 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -228,8 +228,9 @@ class DatabaseWrapper(BaseDatabaseWrapper):
# TO_CHAR().
cursor.execute(
"ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS'"
- " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'"
- + (" TIME_ZONE = 'UTC'" if settings.USE_TZ else ''))
+ " NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF'" +
+ (" TIME_ZONE = 'UTC'" if settings.USE_TZ else '')
+ )
cursor.close()
if 'operators' not in self.__dict__:
# Ticket #14149: Check whether our LIKE implementation will
diff --git a/django/db/backends/oracle/compiler.py b/django/db/backends/oracle/compiler.py
index 7073dc34e8..45b5fc2591 100644
--- a/django/db/backends/oracle/compiler.py
+++ b/django/db/backends/oracle/compiler.py
@@ -14,8 +14,7 @@ class SQLCompiler(compiler.SQLCompiler):
"""
# The `do_offset` flag indicates whether we need to construct
# the SQL needed to use limit/offset with Oracle.
- do_offset = with_limits and (self.query.high_mark is not None
- or self.query.low_mark)
+ do_offset = with_limits and (self.query.high_mark is not None or self.query.low_mark)
if not do_offset:
sql, params = super(SQLCompiler, self).as_sql(
with_limits=False,
diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py
index 90b7090464..103adb50f6 100644
--- a/django/db/backends/postgresql/introspection.py
+++ b/django/db/backends/postgresql/introspection.py
@@ -78,9 +78,13 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
WHERE table_name = %s""", [table_name])
field_map = {line[0]: line[1:] for line in cursor.fetchall()}
cursor.execute("SELECT * FROM %s LIMIT 1" % self.connection.ops.quote_name(table_name))
- return [FieldInfo(*((force_text(line[0]),) + line[1:6]
- + (field_map[force_text(line[0])][0] == 'YES', field_map[force_text(line[0])][1])))
- for line in cursor.description]
+ return [
+ FieldInfo(*(
+ (force_text(line[0]),) +
+ line[1:6] +
+ (field_map[force_text(line[0])][0] == 'YES', field_map[force_text(line[0])][1])
+ )) for line in cursor.description
+ ]
def get_relations(self, cursor, table_name):
"""
diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py
index b7716b208f..943bd35d34 100644
--- a/django/db/migrations/autodetector.py
+++ b/django/db/migrations/autodetector.py
@@ -215,8 +215,8 @@ class MigrationAutodetector(object):
old_model_state = self.from_state.models[app_label, old_model_name]
for field_name, field in old_model_state.fields:
old_field = self.old_apps.get_model(app_label, old_model_name)._meta.get_field(field_name)
- if (hasattr(old_field, "remote_field") and getattr(old_field.remote_field, "through", None)
- and not old_field.remote_field.through._meta.auto_created):
+ if (hasattr(old_field, "remote_field") and getattr(old_field.remote_field, "through", None) and
+ not old_field.remote_field.through._meta.auto_created):
through_key = (
old_field.remote_field.through._meta.app_label,
old_field.remote_field.through._meta.model_name,
@@ -509,8 +509,8 @@ class MigrationAutodetector(object):
related_fields[field.name] = field
# through will be none on M2Ms on swapped-out models;
# we can treat lack of through as auto_created=True, though.
- if (getattr(field.remote_field, "through", None)
- and not field.remote_field.through._meta.auto_created):
+ if (getattr(field.remote_field, "through", None) and
+ not field.remote_field.through._meta.auto_created):
related_fields[field.name] = field
for field in model_opts.local_many_to_many:
if field.remote_field.model:
@@ -671,8 +671,8 @@ class MigrationAutodetector(object):
related_fields[field.name] = field
# through will be none on M2Ms on swapped-out models;
# we can treat lack of through as auto_created=True, though.
- if (getattr(field.remote_field, "through", None)
- and not field.remote_field.through._meta.auto_created):
+ if (getattr(field.remote_field, "through", None) and
+ not field.remote_field.through._meta.auto_created):
related_fields[field.name] = field
for field in model._meta.local_many_to_many:
if field.remote_field.model:
diff --git a/django/db/migrations/graph.py b/django/db/migrations/graph.py
index f324ba5551..6ba4ec129b 100644
--- a/django/db/migrations/graph.py
+++ b/django/db/migrations/graph.py
@@ -206,8 +206,7 @@ class MigrationGraph(object):
"""
roots = set()
for node in self.nodes:
- if (not any(key[0] == node[0] for key in self.node_map[node].parents)
- and (not app or app == node[0])):
+ if not any(key[0] == node[0] for key in self.node_map[node].parents) and (not app or app == node[0]):
roots.add(node)
return sorted(roots)
@@ -221,8 +220,7 @@ class MigrationGraph(object):
"""
leaves = set()
for node in self.nodes:
- if (not any(key[0] == node[0] for key in self.node_map[node].children)
- and (not app or app == node[0])):
+ if not any(key[0] == node[0] for key in self.node_map[node].children) and (not app or app == node[0]):
leaves.add(node)
return sorted(leaves)
diff --git a/django/db/models/base.py b/django/db/models/base.py
index 977c5bc989..7b0b68f983 100644
--- a/django/db/models/base.py
+++ b/django/db/models/base.py
@@ -397,8 +397,8 @@ class Model(six.with_metaclass(ModelBase)):
# data-descriptor object (DeferredAttribute) without triggering its
# __get__ method.
if (field.attname not in kwargs and
- (isinstance(self.__class__.__dict__.get(field.attname), DeferredAttribute)
- or field.column is None)):
+ (isinstance(self.__class__.__dict__.get(field.attname), DeferredAttribute) or
+ field.column is None)):
# This field will be populated on request.
continue
if kwargs:
@@ -753,8 +753,8 @@ class Model(six.with_metaclass(ModelBase)):
meta = cls._meta
for parent, field in meta.parents.items():
# Make sure the link fields are synced between parent and self.
- if (field and getattr(self, parent._meta.pk.attname) is None
- and getattr(self, field.attname) is not None):
+ if (field and getattr(self, parent._meta.pk.attname) is None and
+ getattr(self, field.attname) is not None):
setattr(self, parent._meta.pk.attname, getattr(self, field.attname))
self._save_parents(cls=parent, using=using, update_fields=update_fields)
self._save_table(cls=parent, using=using, update_fields=update_fields)
@@ -1589,8 +1589,7 @@ class Model(six.with_metaclass(ModelBase)):
# Check if auto-generated name for the field is too long
# for the database.
- if (f.db_column is None and column_name is not None
- and len(column_name) > allowed_len):
+ if f.db_column is None and column_name is not None and len(column_name) > allowed_len:
errors.append(
checks.Error(
'Autogenerated column name too long for field "%s". '
@@ -1607,8 +1606,7 @@ class Model(six.with_metaclass(ModelBase)):
# for the database.
for m2m in f.remote_field.through._meta.local_fields:
_, rel_name = m2m.get_attname_column()
- if (m2m.db_column is None and rel_name is not None
- and len(rel_name) > allowed_len):
+ if m2m.db_column is None and rel_name is not None and len(rel_name) > allowed_len:
errors.append(
checks.Error(
'Autogenerated column name too long for M2M field '
diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py
index 1c3b7203b5..7c9db0d87a 100644
--- a/django/db/models/deletion.py
+++ b/django/db/models/deletion.py
@@ -132,9 +132,9 @@ class Collector(object):
if not (hasattr(objs, 'model') and hasattr(objs, '_raw_delete')):
return False
model = objs.model
- if (signals.pre_delete.has_listeners(model)
- or signals.post_delete.has_listeners(model)
- or signals.m2m_changed.has_listeners(model)):
+ if (signals.pre_delete.has_listeners(model) or
+ signals.post_delete.has_listeners(model) or
+ signals.m2m_changed.has_listeners(model)):
return False
# The use of from_field comes from the need to avoid cascade back to
# parent when parent delete is cascading to child.
diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py
index 20268ee660..89d64197e6 100644
--- a/django/db/models/expressions.py
+++ b/django/db/models/expressions.py
@@ -395,8 +395,8 @@ class CombinedExpression(Expression):
except FieldError:
rhs_output = None
if (not connection.features.has_native_duration_field and
- ((lhs_output and lhs_output.get_internal_type() == 'DurationField')
- or (rhs_output and rhs_output.get_internal_type() == 'DurationField'))):
+ ((lhs_output and lhs_output.get_internal_type() == 'DurationField') or
+ (rhs_output and rhs_output.get_internal_type() == 'DurationField'))):
return DurationExpression(self.lhs, self.connector, self.rhs).as_sql(compiler, connection)
if (lhs_output and rhs_output and self.connector == self.SUB and
lhs_output.get_internal_type() in {'DateField', 'DateTimeField', 'TimeField'} and
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 0e4250544b..14f7058285 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -1878,8 +1878,7 @@ class IntegerField(Field):
return int(value)
def get_prep_lookup(self, lookup_type, value):
- if ((lookup_type == 'gte' or lookup_type == 'lt')
- and isinstance(value, float)):
+ if lookup_type in ('gte', 'lt') and isinstance(value, float):
value = math.ceil(value)
return super(IntegerField, self).get_prep_lookup(lookup_type, value)
diff --git a/django/db/models/fields/files.py b/django/db/models/fields/files.py
index a222e491af..763fdd8093 100644
--- a/django/db/models/fields/files.py
+++ b/django/db/models/fields/files.py
@@ -440,8 +440,8 @@ class ImageField(FileField):
return
dimension_fields_filled = not(
- (self.width_field and not getattr(instance, self.width_field))
- or (self.height_field and not getattr(instance, self.height_field))
+ (self.width_field and not getattr(instance, self.width_field)) or
+ (self.height_field and not getattr(instance, self.height_field))
)
# When both dimension fields have values, we are most likely loading
# data from the database or updating an image field that already had
diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py
index 9a7812497b..5634704fed 100644
--- a/django/db/models/lookups.py
+++ b/django/db/models/lookups.py
@@ -275,8 +275,8 @@ class PatternLookup(BuiltinLookup):
# So, for Python values we don't need any special pattern, but for
# SQL reference values or SQL transformations we need the correct
# pattern added.
- if (hasattr(self.rhs, 'get_compiler') or hasattr(self.rhs, 'as_sql')
- or hasattr(self.rhs, '_as_sql') or self.bilateral_transforms):
+ if (hasattr(self.rhs, 'get_compiler') or hasattr(self.rhs, 'as_sql') or
+ hasattr(self.rhs, '_as_sql') or self.bilateral_transforms):
pattern = connection.pattern_ops[self.lookup_name].format(connection.pattern_esc)
return pattern.format(rhs)
else:
diff --git a/django/db/models/options.py b/django/db/models/options.py
index 4fdcc025f7..a0b2f56082 100644
--- a/django/db/models/options.py
+++ b/django/db/models/options.py
@@ -384,9 +384,9 @@ class Options(object):
return make_immutable_fields_list(
"fields",
- (f for f in self._get_fields(reverse=False) if
- is_not_an_m2m_field(f) and is_not_a_generic_relation(f)
- and is_not_a_generic_foreign_key(f))
+ (f for f in self._get_fields(reverse=False)
+ if is_not_an_m2m_field(f) and is_not_a_generic_relation(f) and
+ is_not_a_generic_foreign_key(f))
)
@cached_property
diff --git a/django/db/models/query.py b/django/db/models/query.py
index cb9e7a9ce7..150d77bc91 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -443,8 +443,8 @@ class QuerySet(object):
objs = list(objs)
self._populate_pk_values(objs)
with transaction.atomic(using=self.db, savepoint=False):
- if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk
- and self.model._meta.has_auto_field):
+ if (connection.features.can_combine_inserts_with_and_without_auto_increment_pk and
+ self.model._meta.has_auto_field):
self._batched_insert(objs, fields, batch_size)
else:
objs_with_pk, objs_without_pk = partition(lambda o: o.pk is None, objs)
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 1223e9a109..4a5eb1701a 100644
--- a/django/db/models/sql/query.py
+++ b/django/db/models/sql/query.py
@@ -735,9 +735,7 @@ class Query(object):
# Only the first alias (skipped above) should have None join_type
assert self.alias_map[alias].join_type is not None
parent_alias = self.alias_map[alias].parent_alias
- parent_louter = (
- parent_alias
- and self.alias_map[parent_alias].join_type == LOUTER)
+ parent_louter = parent_alias and self.alias_map[parent_alias].join_type == LOUTER
already_louter = self.alias_map[alias].join_type == LOUTER
if ((self.alias_map[alias].nullable or parent_louter) and
not already_louter):
@@ -746,8 +744,8 @@ class Query(object):
# refer to this one.
aliases.extend(
join for join in self.alias_map.keys()
- if (self.alias_map[join].parent_alias == alias
- and join not in aliases))
+ if self.alias_map[join].parent_alias == alias and join not in aliases
+ )
def demote_joins(self, aliases):
"""
@@ -1641,8 +1639,7 @@ class Query(object):
# from the model on which the lookup failed.
raise
else:
- names = sorted(list(get_field_names_from_opts(opts)) + list(self.extra)
- + list(self.annotation_select))
+ names = sorted(list(get_field_names_from_opts(opts)) + list(self.extra) + list(self.annotation_select))
raise FieldError("Cannot resolve keyword %r into field. "
"Choices are: %s" % (name, ", ".join(names)))
@@ -1963,8 +1960,7 @@ class Query(object):
# used. The proper fix would be to defer all decisions where
# is_nullable() is needed to the compiler stage, but that is not easy
# to do currently.
- if ((connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls)
- and field.empty_strings_allowed):
+ if connections[DEFAULT_DB_ALIAS].features.interprets_empty_strings_as_nulls and field.empty_strings_allowed:
return True
else:
return field.null