Refs #28909 -- Simplifed code using unpacking generalizations.
This commit is contained in:
parent
4fc8fb7dda
commit
8ef8bc0f64
|
@ -389,7 +389,7 @@ class Apps:
|
||||||
# to lazy_model_operation() along with the remaining model args and
|
# to lazy_model_operation() along with the remaining model args and
|
||||||
# repeat until all models are loaded and all arguments are applied.
|
# repeat until all models are loaded and all arguments are applied.
|
||||||
else:
|
else:
|
||||||
next_model, more_models = model_keys[0], model_keys[1:]
|
next_model, *more_models = model_keys
|
||||||
|
|
||||||
# This will be executed after the class corresponding to next_model
|
# This will be executed after the class corresponding to next_model
|
||||||
# has been imported and registered. The `func` attribute provides
|
# has been imported and registered. The `func` attribute provides
|
||||||
|
|
|
@ -182,7 +182,7 @@ class UserSettingsHolder:
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return sorted(
|
return sorted(
|
||||||
s for s in list(self.__dict__) + dir(self.default_settings)
|
s for s in [*self.__dict__, *dir(self.default_settings)]
|
||||||
if s not in self._deleted
|
if s not in self._deleted
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
|
||||||
kwargs['widget'] = AutocompleteSelectMultiple(db_field.remote_field, self.admin_site, using=db)
|
kwargs['widget'] = AutocompleteSelectMultiple(db_field.remote_field, self.admin_site, using=db)
|
||||||
elif db_field.name in self.raw_id_fields:
|
elif db_field.name in self.raw_id_fields:
|
||||||
kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.remote_field, self.admin_site, using=db)
|
kwargs['widget'] = widgets.ManyToManyRawIdWidget(db_field.remote_field, self.admin_site, using=db)
|
||||||
elif db_field.name in list(self.filter_vertical) + list(self.filter_horizontal):
|
elif db_field.name in [*self.filter_vertical, *self.filter_horizontal]:
|
||||||
kwargs['widget'] = widgets.FilteredSelectMultiple(
|
kwargs['widget'] = widgets.FilteredSelectMultiple(
|
||||||
db_field.verbose_name,
|
db_field.verbose_name,
|
||||||
db_field.name in self.filter_vertical
|
db_field.name in self.filter_vertical
|
||||||
|
@ -318,7 +318,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass):
|
||||||
return self.fields
|
return self.fields
|
||||||
# _get_form_for_get_fields() is implemented in subclasses.
|
# _get_form_for_get_fields() is implemented in subclasses.
|
||||||
form = self._get_form_for_get_fields(request, obj)
|
form = self._get_form_for_get_fields(request, obj)
|
||||||
return list(form.base_fields) + list(self.get_readonly_fields(request, obj))
|
return [*form.base_fields, *self.get_readonly_fields(request, obj)]
|
||||||
|
|
||||||
def get_fieldsets(self, request, obj=None):
|
def get_fieldsets(self, request, obj=None):
|
||||||
"""
|
"""
|
||||||
|
@ -724,7 +724,7 @@ class ModelAdmin(BaseModelAdmin):
|
||||||
list_display_links = self.get_list_display_links(request, list_display)
|
list_display_links = self.get_list_display_links(request, list_display)
|
||||||
# Add the action checkboxes if any actions are available.
|
# Add the action checkboxes if any actions are available.
|
||||||
if self.get_actions(request):
|
if self.get_actions(request):
|
||||||
list_display = ['action_checkbox'] + list(list_display)
|
list_display = ['action_checkbox', *list_display]
|
||||||
sortable_by = self.get_sortable_by(request)
|
sortable_by = self.get_sortable_by(request)
|
||||||
ChangeList = self.get_changelist(request)
|
ChangeList = self.get_changelist(request)
|
||||||
return ChangeList(
|
return ChangeList(
|
||||||
|
|
|
@ -278,7 +278,7 @@ class ModelDetailView(BaseAdminDocsView):
|
||||||
# join it with '='. Use repr() so that strings will be
|
# join it with '='. Use repr() so that strings will be
|
||||||
# correctly displayed.
|
# correctly displayed.
|
||||||
print_arguments = ', '.join([
|
print_arguments = ', '.join([
|
||||||
'='.join(list(arg_el[:1]) + [repr(el) for el in arg_el[1:]])
|
'='.join([arg_el[0], *map(repr, arg_el[1:])])
|
||||||
for arg_el in arguments
|
for arg_el in arguments
|
||||||
])
|
])
|
||||||
methods.append({
|
methods.append({
|
||||||
|
|
|
@ -15,9 +15,7 @@ def _get_all_permissions(opts):
|
||||||
"""
|
"""
|
||||||
Return (codename, name) for all permissions in the given opts.
|
Return (codename, name) for all permissions in the given opts.
|
||||||
"""
|
"""
|
||||||
builtin = _get_builtin_permissions(opts)
|
return [*_get_builtin_permissions(opts), *opts.permissions]
|
||||||
custom = list(opts.permissions)
|
|
||||||
return builtin + custom
|
|
||||||
|
|
||||||
|
|
||||||
def _get_builtin_permissions(opts):
|
def _get_builtin_permissions(opts):
|
||||||
|
|
|
@ -109,11 +109,11 @@ class ListMixin:
|
||||||
# ### Special methods for arithmetic operations ###
|
# ### Special methods for arithmetic operations ###
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
'add another list-like object'
|
'add another list-like object'
|
||||||
return self.__class__(list(self) + list(other))
|
return self.__class__([*self, *other])
|
||||||
|
|
||||||
def __radd__(self, other):
|
def __radd__(self, other):
|
||||||
'add to another list-like object'
|
'add to another list-like object'
|
||||||
return other.__class__(list(other) + list(self))
|
return other.__class__([*other, *self])
|
||||||
|
|
||||||
def __iadd__(self, other):
|
def __iadd__(self, other):
|
||||||
'add another list-like object to self'
|
'add another list-like object to self'
|
||||||
|
|
|
@ -31,8 +31,7 @@ class Polygon(GEOSGeometry):
|
||||||
return
|
return
|
||||||
|
|
||||||
# Getting the ext_ring and init_holes parameters from the argument list
|
# Getting the ext_ring and init_holes parameters from the argument list
|
||||||
ext_ring = args[0]
|
ext_ring, *init_holes = args
|
||||||
init_holes = args[1:]
|
|
||||||
n_holes = len(init_holes)
|
n_holes = len(init_holes)
|
||||||
|
|
||||||
# If initialized as Polygon(shell, (LinearRing, LinearRing)) [for backward-compatibility]
|
# If initialized as Polygon(shell, (LinearRing, LinearRing)) [for backward-compatibility]
|
||||||
|
@ -44,7 +43,7 @@ class Polygon(GEOSGeometry):
|
||||||
init_holes = init_holes[0]
|
init_holes = init_holes[0]
|
||||||
n_holes = len(init_holes)
|
n_holes = len(init_holes)
|
||||||
|
|
||||||
polygon = self._create_polygon(n_holes + 1, (ext_ring,) + init_holes)
|
polygon = self._create_polygon(n_holes + 1, [ext_ring, *init_holes])
|
||||||
super().__init__(polygon, **kwargs)
|
super().__init__(polygon, **kwargs)
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Serializer(JSONSerializer):
|
||||||
self.srid = self.json_kwargs.pop('srid', 4326)
|
self.srid = self.json_kwargs.pop('srid', 4326)
|
||||||
if (self.selected_fields is not None and self.geometry_field is not None and
|
if (self.selected_fields is not None and self.geometry_field is not None and
|
||||||
self.geometry_field not in self.selected_fields):
|
self.geometry_field not in self.selected_fields):
|
||||||
self.selected_fields = list(self.selected_fields) + [self.geometry_field]
|
self.selected_fields = [*self.selected_fields, self.geometry_field]
|
||||||
|
|
||||||
def start_serialization(self):
|
def start_serialization(self):
|
||||||
self._init_options()
|
self._init_options()
|
||||||
|
|
|
@ -28,8 +28,7 @@ class ArrayField(CheckFieldDefaultMixin, Field):
|
||||||
self.base_field = base_field
|
self.base_field = base_field
|
||||||
self.size = size
|
self.size = size
|
||||||
if self.size:
|
if self.size:
|
||||||
self.default_validators = self.default_validators[:]
|
self.default_validators = [*self.default_validators, ArrayMaxLengthValidator(self.size)]
|
||||||
self.default_validators.append(ArrayMaxLengthValidator(self.size))
|
|
||||||
# For performance, only add a from_db_value() method if the base field
|
# For performance, only add a from_db_value() method if the base field
|
||||||
# implements it.
|
# implements it.
|
||||||
if hasattr(self.base_field, 'from_db_value'):
|
if hasattr(self.base_field, 'from_db_value'):
|
||||||
|
|
|
@ -143,9 +143,10 @@ class WSGIHandler(base.BaseHandler):
|
||||||
response._handler_class = self.__class__
|
response._handler_class = self.__class__
|
||||||
|
|
||||||
status = '%d %s' % (response.status_code, response.reason_phrase)
|
status = '%d %s' % (response.status_code, response.reason_phrase)
|
||||||
response_headers = list(response.items())
|
response_headers = [
|
||||||
for c in response.cookies.values():
|
*response.items(),
|
||||||
response_headers.append(('Set-Cookie', c.output(header='')))
|
*(('Set-Cookie', c.output(header='')) for c in response.cookies.values()),
|
||||||
|
]
|
||||||
start_response(status, response_headers)
|
start_response(status, response_headers)
|
||||||
if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
|
if getattr(response, 'file_to_stream', None) is not None and environ.get('wsgi.file_wrapper'):
|
||||||
response = environ['wsgi.file_wrapper'](response.file_to_stream)
|
response = environ['wsgi.file_wrapper'](response.file_to_stream)
|
||||||
|
|
|
@ -257,7 +257,7 @@ class ManagementUtility:
|
||||||
except IndexError:
|
except IndexError:
|
||||||
curr = ''
|
curr = ''
|
||||||
|
|
||||||
subcommands = list(get_commands()) + ['help']
|
subcommands = [*get_commands(), 'help']
|
||||||
options = [('--help', False)]
|
options = [('--help', False)]
|
||||||
|
|
||||||
# subcommand
|
# subcommand
|
||||||
|
|
|
@ -735,9 +735,7 @@ class AddIndex(IndexOperation):
|
||||||
|
|
||||||
def state_forwards(self, app_label, state):
|
def state_forwards(self, app_label, state):
|
||||||
model_state = state.models[app_label, self.model_name_lower]
|
model_state = state.models[app_label, self.model_name_lower]
|
||||||
indexes = list(model_state.options[self.option_name])
|
model_state.options[self.option_name] = [*model_state.options[self.option_name], self.index.clone()]
|
||||||
indexes.append(self.index.clone())
|
|
||||||
model_state.options[self.option_name] = indexes
|
|
||||||
state.reload_model(app_label, self.model_name_lower, delay=True)
|
state.reload_model(app_label, self.model_name_lower, delay=True)
|
||||||
|
|
||||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
|
@ -820,9 +818,7 @@ class AddConstraint(IndexOperation):
|
||||||
|
|
||||||
def state_forwards(self, app_label, state):
|
def state_forwards(self, app_label, state):
|
||||||
model_state = state.models[app_label, self.model_name_lower]
|
model_state = state.models[app_label, self.model_name_lower]
|
||||||
constraints = list(model_state.options[self.option_name])
|
model_state.options[self.option_name] = [*model_state.options[self.option_name], self.constraint]
|
||||||
constraints.append(self.constraint)
|
|
||||||
model_state.options[self.option_name] = constraints
|
|
||||||
|
|
||||||
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
def database_forwards(self, app_label, schema_editor, from_state, to_state):
|
||||||
model = to_state.apps.get_model(app_label, self.model_name)
|
model = to_state.apps.get_model(app_label, self.model_name)
|
||||||
|
|
|
@ -261,14 +261,14 @@ class StateApps(Apps):
|
||||||
self.real_models.append(ModelState.from_model(model, exclude_rels=True))
|
self.real_models.append(ModelState.from_model(model, exclude_rels=True))
|
||||||
# Populate the app registry with a stub for each application.
|
# Populate the app registry with a stub for each application.
|
||||||
app_labels = {model_state.app_label for model_state in models.values()}
|
app_labels = {model_state.app_label for model_state in models.values()}
|
||||||
app_configs = [AppConfigStub(label) for label in sorted(real_apps + list(app_labels))]
|
app_configs = [AppConfigStub(label) for label in sorted([*real_apps, *app_labels])]
|
||||||
super().__init__(app_configs)
|
super().__init__(app_configs)
|
||||||
|
|
||||||
# The lock gets in the way of copying as implemented in clone(), which
|
# The lock gets in the way of copying as implemented in clone(), which
|
||||||
# is called whenever Django duplicates a StateApps before updating it.
|
# is called whenever Django duplicates a StateApps before updating it.
|
||||||
self._lock = None
|
self._lock = None
|
||||||
|
|
||||||
self.render_multiple(list(models.values()) + self.real_models)
|
self.render_multiple([*models.values(), *self.real_models])
|
||||||
|
|
||||||
# There shouldn't be any operations pending at this point.
|
# There shouldn't be any operations pending at this point.
|
||||||
from django.core.checks.model_checks import _check_lazy_references
|
from django.core.checks.model_checks import _check_lazy_references
|
||||||
|
|
|
@ -947,8 +947,7 @@ class Case(Expression):
|
||||||
return self.cases + [self.default]
|
return self.cases + [self.default]
|
||||||
|
|
||||||
def set_source_expressions(self, exprs):
|
def set_source_expressions(self, exprs):
|
||||||
self.cases = exprs[:-1]
|
*self.cases, self.default = exprs
|
||||||
self.default = exprs[-1]
|
|
||||||
|
|
||||||
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
|
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False):
|
||||||
c = self.copy()
|
c = self.copy()
|
||||||
|
|
|
@ -96,13 +96,12 @@ class ValuesIterable(BaseIterable):
|
||||||
query = queryset.query
|
query = queryset.query
|
||||||
compiler = query.get_compiler(queryset.db)
|
compiler = query.get_compiler(queryset.db)
|
||||||
|
|
||||||
field_names = list(query.values_select)
|
|
||||||
extra_names = list(query.extra_select)
|
|
||||||
annotation_names = list(query.annotation_select)
|
|
||||||
|
|
||||||
# extra(select=...) cols are always at the start of the row.
|
# extra(select=...) cols are always at the start of the row.
|
||||||
names = extra_names + field_names + annotation_names
|
names = [
|
||||||
|
*query.extra_select,
|
||||||
|
*query.values_select,
|
||||||
|
*query.annotation_select,
|
||||||
|
]
|
||||||
indexes = range(len(names))
|
indexes = range(len(names))
|
||||||
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
|
for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
|
||||||
yield {names[i]: row[i] for i in indexes}
|
yield {names[i]: row[i] for i in indexes}
|
||||||
|
@ -120,14 +119,13 @@ class ValuesListIterable(BaseIterable):
|
||||||
compiler = query.get_compiler(queryset.db)
|
compiler = query.get_compiler(queryset.db)
|
||||||
|
|
||||||
if queryset._fields:
|
if queryset._fields:
|
||||||
field_names = list(query.values_select)
|
|
||||||
extra_names = list(query.extra_select)
|
|
||||||
annotation_names = list(query.annotation_select)
|
|
||||||
|
|
||||||
# extra(select=...) cols are always at the start of the row.
|
# extra(select=...) cols are always at the start of the row.
|
||||||
names = extra_names + field_names + annotation_names
|
names = [
|
||||||
|
*query.extra_select,
|
||||||
fields = list(queryset._fields) + [f for f in annotation_names if f not in queryset._fields]
|
*query.values_select,
|
||||||
|
*query.annotation_select,
|
||||||
|
]
|
||||||
|
fields = [*queryset._fields, *(f for f in query.annotation_select if f not in queryset._fields)]
|
||||||
if fields != names:
|
if fields != names:
|
||||||
# Reorder according to fields.
|
# Reorder according to fields.
|
||||||
index_map = {name: idx for idx, name in enumerate(names)}
|
index_map = {name: idx for idx, name in enumerate(names)}
|
||||||
|
@ -352,7 +350,7 @@ class QuerySet:
|
||||||
"""
|
"""
|
||||||
if self.query.distinct_fields:
|
if self.query.distinct_fields:
|
||||||
raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
|
raise NotImplementedError("aggregate() + distinct(fields) not implemented.")
|
||||||
self._validate_values_are_expressions(args + tuple(kwargs.values()), method_name='aggregate')
|
self._validate_values_are_expressions((*args, *kwargs.values()), method_name='aggregate')
|
||||||
for arg in args:
|
for arg in args:
|
||||||
# The default_alias property raises TypeError if default_alias
|
# The default_alias property raises TypeError if default_alias
|
||||||
# can't be set automatically or AttributeError if it isn't an
|
# can't be set automatically or AttributeError if it isn't an
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Q(tree.Node):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
connector = kwargs.pop('_connector', None)
|
connector = kwargs.pop('_connector', None)
|
||||||
negated = kwargs.pop('_negated', False)
|
negated = kwargs.pop('_negated', False)
|
||||||
super().__init__(children=list(args) + sorted(kwargs.items()), connector=connector, negated=negated)
|
super().__init__(children=[*args, *sorted(kwargs.items())], connector=connector, negated=negated)
|
||||||
|
|
||||||
def _combine(self, other, conn):
|
def _combine(self, other, conn):
|
||||||
if not isinstance(other, Q):
|
if not isinstance(other, Q):
|
||||||
|
|
|
@ -1096,12 +1096,11 @@ class Query:
|
||||||
and get_transform().
|
and get_transform().
|
||||||
"""
|
"""
|
||||||
# __exact is the default lookup if one isn't given.
|
# __exact is the default lookup if one isn't given.
|
||||||
lookups = lookups or ['exact']
|
*transforms, lookup_name = lookups or ['exact']
|
||||||
for name in lookups[:-1]:
|
for name in transforms:
|
||||||
lhs = self.try_transform(lhs, name)
|
lhs = self.try_transform(lhs, name)
|
||||||
# First try get_lookup() so that the lookup takes precedence if the lhs
|
# First try get_lookup() so that the lookup takes precedence if the lhs
|
||||||
# supports both transform and lookup for the name.
|
# supports both transform and lookup for the name.
|
||||||
lookup_name = lookups[-1]
|
|
||||||
lookup_class = lhs.get_lookup(lookup_name)
|
lookup_class = lhs.get_lookup(lookup_name)
|
||||||
if not lookup_class:
|
if not lookup_class:
|
||||||
if lhs.field.is_relation:
|
if lhs.field.is_relation:
|
||||||
|
@ -1406,11 +1405,11 @@ class Query:
|
||||||
# one step.
|
# one step.
|
||||||
pos -= 1
|
pos -= 1
|
||||||
if pos == -1 or fail_on_missing:
|
if pos == -1 or fail_on_missing:
|
||||||
field_names = list(get_field_names_from_opts(opts))
|
available = sorted([
|
||||||
available = sorted(
|
*get_field_names_from_opts(opts),
|
||||||
field_names + list(self.annotation_select) +
|
*self.annotation_select,
|
||||||
list(self._filtered_relations)
|
*self._filtered_relations,
|
||||||
)
|
])
|
||||||
raise FieldError("Cannot resolve keyword '%s' into field. "
|
raise FieldError("Cannot resolve keyword '%s' into field. "
|
||||||
"Choices are: %s" % (name, ", ".join(available)))
|
"Choices are: %s" % (name, ", ".join(available)))
|
||||||
break
|
break
|
||||||
|
@ -1776,10 +1775,10 @@ class Query:
|
||||||
# from the model on which the lookup failed.
|
# from the model on which the lookup failed.
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
names = sorted(
|
names = sorted([
|
||||||
list(get_field_names_from_opts(opts)) + list(self.extra) +
|
*get_field_names_from_opts(opts), *self.extra,
|
||||||
list(self.annotation_select) + list(self._filtered_relations)
|
*self.annotation_select, *self._filtered_relations
|
||||||
)
|
])
|
||||||
raise FieldError("Cannot resolve keyword %r into field. "
|
raise FieldError("Cannot resolve keyword %r into field. "
|
||||||
"Choices are: %s" % (name, ", ".join(names)))
|
"Choices are: %s" % (name, ", ".join(names)))
|
||||||
|
|
||||||
|
|
|
@ -107,8 +107,7 @@ class Engine:
|
||||||
|
|
||||||
def find_template_loader(self, loader):
|
def find_template_loader(self, loader):
|
||||||
if isinstance(loader, (tuple, list)):
|
if isinstance(loader, (tuple, list)):
|
||||||
args = list(loader[1:])
|
loader, *args = loader
|
||||||
loader = loader[0]
|
|
||||||
else:
|
else:
|
||||||
args = []
|
args = []
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ class Element:
|
||||||
return self.children == element.children
|
return self.children == element.children
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.name,) + tuple(a for a in self.attributes))
|
return hash((self.name, *(a for a in self.attributes)))
|
||||||
|
|
||||||
def _count(self, element, count=True):
|
def _count(self, element, count=True):
|
||||||
if not isinstance(element, str):
|
if not isinstance(element, str):
|
||||||
|
|
|
@ -614,8 +614,7 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
def _assertFooMessage(self, func, cm_attr, expected_exception, expected_message, *args, **kwargs):
|
def _assertFooMessage(self, func, cm_attr, expected_exception, expected_message, *args, **kwargs):
|
||||||
callable_obj = None
|
callable_obj = None
|
||||||
if args:
|
if args:
|
||||||
callable_obj = args[0]
|
callable_obj, *args = args
|
||||||
args = args[1:]
|
|
||||||
cm = self._assert_raises_or_warns_cm(func, cm_attr, expected_exception, expected_message)
|
cm = self._assert_raises_or_warns_cm(func, cm_attr, expected_exception, expected_message)
|
||||||
# Assertion used in context manager fashion.
|
# Assertion used in context manager fashion.
|
||||||
if callable_obj is None:
|
if callable_obj is None:
|
||||||
|
|
|
@ -120,7 +120,7 @@ def setup_test_environment(debug=None):
|
||||||
|
|
||||||
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
|
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
|
||||||
# Add the default host of the test client.
|
# Add the default host of the test client.
|
||||||
settings.ALLOWED_HOSTS = list(settings.ALLOWED_HOSTS) + ['testserver']
|
settings.ALLOWED_HOSTS = [*settings.ALLOWED_HOSTS, 'testserver']
|
||||||
|
|
||||||
saved_data.debug = settings.DEBUG
|
saved_data.debug = settings.DEBUG
|
||||||
settings.DEBUG = debug
|
settings.DEBUG = debug
|
||||||
|
|
|
@ -133,8 +133,9 @@ def format_html_join(sep, format_string, args_generator):
|
||||||
for u in users))
|
for u in users))
|
||||||
"""
|
"""
|
||||||
return mark_safe(conditional_escape(sep).join(
|
return mark_safe(conditional_escape(sep).join(
|
||||||
format_html(format_string, *tuple(args))
|
format_html(format_string, *args)
|
||||||
for args in args_generator))
|
for args in args_generator
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
@keep_lazy_text
|
@keep_lazy_text
|
||||||
|
|
|
@ -360,7 +360,7 @@ def all_locale_paths():
|
||||||
locale_path = os.path.join(app_config.path, 'locale')
|
locale_path = os.path.join(app_config.path, 'locale')
|
||||||
if os.path.exists(locale_path):
|
if os.path.exists(locale_path):
|
||||||
app_paths.append(locale_path)
|
app_paths.append(locale_path)
|
||||||
return [globalpath] + list(settings.LOCALE_PATHS) + app_paths
|
return [globalpath, *settings.LOCALE_PATHS, *app_paths]
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(maxsize=1000)
|
@functools.lru_cache(maxsize=1000)
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Node:
|
||||||
)
|
)
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.__class__, self.connector, self.negated) + tuple([
|
return hash((self.__class__, self.connector, self.negated, *[
|
||||||
tuple(child) if isinstance(child, list) else child
|
tuple(child) if isinstance(child, list) else child
|
||||||
for child in self.children
|
for child in self.children
|
||||||
]))
|
]))
|
||||||
|
|
|
@ -99,7 +99,7 @@ attribute. The ``name`` attribute of the base class will be ignored.
|
||||||
In order to fully serialize your ``Restaurant`` instances, you will need to
|
In order to fully serialize your ``Restaurant`` instances, you will need to
|
||||||
serialize the ``Place`` models as well::
|
serialize the ``Place`` models as well::
|
||||||
|
|
||||||
all_objects = list(Restaurant.objects.all()) + list(Place.objects.all())
|
all_objects = [*Restaurant.objects.all(), *Place.objects.all()]
|
||||||
data = serializers.serialize('xml', all_objects)
|
data = serializers.serialize('xml', all_objects)
|
||||||
|
|
||||||
Deserializing data
|
Deserializing data
|
||||||
|
|
|
@ -544,8 +544,7 @@ class CustomStorage(FileSystemStorage):
|
||||||
"""
|
"""
|
||||||
Append numbers to duplicate files rather than underscores, like Trac.
|
Append numbers to duplicate files rather than underscores, like Trac.
|
||||||
"""
|
"""
|
||||||
parts = name.split('.')
|
basename, *ext = name.split('.')
|
||||||
basename, ext = parts[0], parts[1:]
|
|
||||||
number = 2
|
number = 2
|
||||||
while self.exists(name):
|
while self.exists(name):
|
||||||
name = '.'.join([basename, str(number)] + ext)
|
name = '.'.join([basename, str(number)] + ext)
|
||||||
|
|
|
@ -1566,7 +1566,7 @@ value="Should escape < & > and <script>alert('xss')</
|
||||||
p = TestForm()
|
p = TestForm()
|
||||||
self.assertEqual(list(p.fields), TestFormMissing.field_order)
|
self.assertEqual(list(p.fields), TestFormMissing.field_order)
|
||||||
p = TestFormInit()
|
p = TestFormInit()
|
||||||
order = list(TestForm.field_order) + ['field1']
|
order = [*TestForm.field_order, 'field1']
|
||||||
self.assertEqual(list(p.fields), order)
|
self.assertEqual(list(p.fields), order)
|
||||||
TestForm.field_order = ['unknown']
|
TestForm.field_order = ['unknown']
|
||||||
p = TestForm()
|
p = TestForm()
|
||||||
|
|
|
@ -476,8 +476,8 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
||||||
Polygon('foo')
|
Polygon('foo')
|
||||||
|
|
||||||
# Polygon(shell, (hole1, ... holeN))
|
# Polygon(shell, (hole1, ... holeN))
|
||||||
rings = tuple(r for r in poly)
|
ext_ring, *int_rings = poly
|
||||||
self.assertEqual(poly, Polygon(rings[0], rings[1:]))
|
self.assertEqual(poly, Polygon(ext_ring, int_rings))
|
||||||
|
|
||||||
# Polygon(shell_tuple, hole_tuple1, ... , hole_tupleN)
|
# Polygon(shell_tuple, hole_tuple1, ... , hole_tupleN)
|
||||||
ring_tuples = tuple(r.tuple for r in poly)
|
ring_tuples = tuple(r.tuple for r in poly)
|
||||||
|
|
|
@ -72,7 +72,7 @@ class ListMixinTest(unittest.TestCase):
|
||||||
return range(-self.limit - b, self.limit + b)
|
return range(-self.limit - b, self.limit + b)
|
||||||
|
|
||||||
def step_range(self):
|
def step_range(self):
|
||||||
return list(range(-1 - self.limit, 0)) + list(range(1, 1 + self.limit))
|
return [*range(-1 - self.limit, 0), *range(1, 1 + self.limit)]
|
||||||
|
|
||||||
def test01_getslice(self):
|
def test01_getslice(self):
|
||||||
'Slice retrieval'
|
'Slice retrieval'
|
||||||
|
@ -172,13 +172,13 @@ class ListMixinTest(unittest.TestCase):
|
||||||
del pl[i:j]
|
del pl[i:j]
|
||||||
del ul[i:j]
|
del ul[i:j]
|
||||||
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d]' % (i, j))
|
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d]' % (i, j))
|
||||||
for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
|
for k in [*range(-Len - 1, 0), *range(1, Len)]:
|
||||||
pl, ul = self.lists_of_len(Len)
|
pl, ul = self.lists_of_len(Len)
|
||||||
del pl[i:j:k]
|
del pl[i:j:k]
|
||||||
del ul[i:j:k]
|
del ul[i:j:k]
|
||||||
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d:%d]' % (i, j, k))
|
self.assertEqual(pl[:], ul[:], 'del slice [%d:%d:%d]' % (i, j, k))
|
||||||
|
|
||||||
for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
|
for k in [*range(-Len - 1, 0), *range(1, Len)]:
|
||||||
pl, ul = self.lists_of_len(Len)
|
pl, ul = self.lists_of_len(Len)
|
||||||
del pl[:i:k]
|
del pl[:i:k]
|
||||||
del ul[:i:k]
|
del ul[:i:k]
|
||||||
|
@ -189,7 +189,7 @@ class ListMixinTest(unittest.TestCase):
|
||||||
del ul[i::k]
|
del ul[i::k]
|
||||||
self.assertEqual(pl[:], ul[:], 'del slice [%d::%d]' % (i, k))
|
self.assertEqual(pl[:], ul[:], 'del slice [%d::%d]' % (i, k))
|
||||||
|
|
||||||
for k in list(range(-Len - 1, 0)) + list(range(1, Len)):
|
for k in [*range(-Len - 1, 0), *range(1, Len)]:
|
||||||
pl, ul = self.lists_of_len(Len)
|
pl, ul = self.lists_of_len(Len)
|
||||||
del pl[::k]
|
del pl[::k]
|
||||||
del ul[::k]
|
del ul[::k]
|
||||||
|
|
|
@ -76,21 +76,21 @@ class FieldFlagsTests(test.SimpleTestCase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
super().setUpClass()
|
super().setUpClass()
|
||||||
cls.fields = (
|
cls.fields = [
|
||||||
list(AllFieldsModel._meta.fields) +
|
*AllFieldsModel._meta.fields,
|
||||||
list(AllFieldsModel._meta.private_fields)
|
*AllFieldsModel._meta.private_fields,
|
||||||
)
|
]
|
||||||
|
|
||||||
cls.all_fields = (
|
cls.all_fields = [
|
||||||
cls.fields +
|
*cls.fields,
|
||||||
list(AllFieldsModel._meta.many_to_many) +
|
*AllFieldsModel._meta.many_to_many,
|
||||||
list(AllFieldsModel._meta.private_fields)
|
*AllFieldsModel._meta.private_fields,
|
||||||
)
|
]
|
||||||
|
|
||||||
cls.fields_and_reverse_objects = (
|
cls.fields_and_reverse_objects = [
|
||||||
cls.all_fields +
|
*cls.all_fields,
|
||||||
list(AllFieldsModel._meta.related_objects)
|
*AllFieldsModel._meta.related_objects,
|
||||||
)
|
]
|
||||||
|
|
||||||
def test_each_field_should_have_a_concrete_attribute(self):
|
def test_each_field_should_have_a_concrete_attribute(self):
|
||||||
self.assertTrue(all(f.concrete.__class__ == bool for f in self.fields))
|
self.assertTrue(all(f.concrete.__class__ == bool for f in self.fields))
|
||||||
|
|
|
@ -111,7 +111,7 @@ simple_one_default.anything = "Expected simple_one_default __dict__"
|
||||||
def simple_unlimited_args(one, two='hi', *args):
|
def simple_unlimited_args(one, two='hi', *args):
|
||||||
"""Expected simple_unlimited_args __doc__"""
|
"""Expected simple_unlimited_args __doc__"""
|
||||||
return "simple_unlimited_args - Expected result: %s" % (
|
return "simple_unlimited_args - Expected result: %s" % (
|
||||||
', '.join(str(arg) for arg in [one, two] + list(args))
|
', '.join(str(arg) for arg in [one, two, *args])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
# Sort the dictionary by key to guarantee the order for testing.
|
# Sort the dictionary by key to guarantee the order for testing.
|
||||||
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
|
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
|
||||||
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
|
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||||
', '.join(str(arg) for arg in [one, two] + list(args)),
|
', '.join(str(arg) for arg in [one, two, *args]),
|
||||||
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,7 @@ def inclusion_unlimited_args(one, two='hi', *args):
|
||||||
return {
|
return {
|
||||||
"result": (
|
"result": (
|
||||||
"inclusion_unlimited_args - Expected result: %s" % (
|
"inclusion_unlimited_args - Expected result: %s" % (
|
||||||
', '.join(str(arg) for arg in [one, two] + list(args))
|
', '.join(str(arg) for arg in [one, two, *args])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ def inclusion_unlimited_args_from_template(one, two='hi', *args):
|
||||||
return {
|
return {
|
||||||
"result": (
|
"result": (
|
||||||
"inclusion_unlimited_args_from_template - Expected result: %s" % (
|
"inclusion_unlimited_args_from_template - Expected result: %s" % (
|
||||||
', '.join(str(arg) for arg in [one, two] + list(args))
|
', '.join(str(arg) for arg in [one, two, *args])
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
||||||
# Sort the dictionary by key to guarantee the order for testing.
|
# Sort the dictionary by key to guarantee the order for testing.
|
||||||
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
|
sorted_kwarg = sorted(kwargs.items(), key=operator.itemgetter(0))
|
||||||
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
|
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||||
', '.join(str(arg) for arg in [one, two] + list(args)),
|
', '.join(str(arg) for arg in [one, two, *args]),
|
||||||
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ from django.utils.baseconv import (
|
||||||
class TestBaseConv(TestCase):
|
class TestBaseConv(TestCase):
|
||||||
|
|
||||||
def test_baseconv(self):
|
def test_baseconv(self):
|
||||||
nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100))
|
nums = [-10 ** 10, 10 ** 10, *range(-100, 100)]
|
||||||
for converter in [base2, base16, base36, base56, base62, base64]:
|
for converter in [base2, base16, base36, base56, base62, base64]:
|
||||||
for i in nums:
|
for i in nums:
|
||||||
self.assertEqual(i, converter.decode(converter.encode(i)))
|
self.assertEqual(i, converter.decode(converter.encode(i)))
|
||||||
|
|
Loading…
Reference in New Issue