Refs #28909 -- Simplifed code using unpacking generalizations.

This commit is contained in:
Nick Pope 2017-12-22 02:05:23 +00:00 committed by Tim Graham
parent ebc4ee3369
commit f3a98224e6
6 changed files with 19 additions and 28 deletions

View File

@ -865,8 +865,7 @@ class BaseDatabaseSchemaEditor:
and a unique digest and suffix.
"""
_, table_name = split_identifier(table_name)
hash_data = [table_name] + list(column_names)
hash_suffix_part = '%s%s' % (self._digest(*hash_data), suffix)
hash_suffix_part = '%s%s' % (self._digest(table_name, *column_names), suffix)
max_length = self.connection.ops.max_name_length() or 200
# If everything fits into max_length, use that name.
index_name = '%s_%s_%s' % (table_name, '_'.join(column_names), hash_suffix_part)

View File

@ -85,22 +85,17 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
fields = []
for line in cursor.description:
col_name = 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].column_default,
field_info[col_name].extra,
field_info[col_name].is_unsigned,
)
))
)
info = field_info[line[0]]
fields.append(FieldInfo(
*line[:3],
to_int(info.max_len) or line[3],
to_int(info.num_prec) or line[4],
to_int(info.num_scale) or line[5],
line[6],
info.column_default,
info.extra,
info.is_unsigned,
))
return fields
def get_sequences(self, cursor, table_name, table_fields=()):

View File

@ -84,13 +84,10 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
name = desc[0]
internal_size, default, is_autofield = field_map[name]
name = name % {} # cx_Oracle, for some reason, doubles percent signs.
description.append(FieldInfo(*(
(name.lower(),) +
desc[1:3] +
(internal_size, desc[4] or 0, desc[5] or 0) +
desc[6:] +
(default, is_autofield)
)))
description.append(FieldInfo(
name.lower(), *desc[1:3], internal_size, desc[4] or 0,
desc[5] or 0, *desc[6:], default, is_autofield,
))
return description
def table_name_converter(self, name):

View File

@ -75,7 +75,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
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(*(line[0:6] + (field_map[line.name][0] == 'YES', field_map[line.name][1])))
FieldInfo(*line[0:6], field_map[line.name][0] == 'YES', field_map[line.name][1])
for line in cursor.description
]

View File

@ -1056,7 +1056,7 @@ class CheckCondition:
self.conditions = conditions
def add_condition(self, condition, reason):
return self.__class__(*self.conditions + ((condition, reason),))
return self.__class__(*self.conditions, (condition, reason))
def __get__(self, instance, cls=None):
# Trigger access for all bases.

View File

@ -9,7 +9,7 @@ from functools import total_ordering, wraps
# CPython) is a type and its instances don't bind.
def curry(_curried_func, *args, **kwargs):
def _curried(*moreargs, **morekwargs):
return _curried_func(*(args + moreargs), **{**kwargs, **morekwargs})
return _curried_func(*args, *moreargs, **{**kwargs, **morekwargs})
return _curried