diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-06-01 16:08:59 -0700 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-06-01 19:08:59 -0400 |
| commit | 2c69824e5ab5ddf4b9964c4cf9f9e16ff3bb7929 (patch) | |
| tree | 65b8e60b858e4f073a04c2bbf976b8f43fe0cff6 /django | |
| parent | edee5a8de6afb34a9247de2bb73ab66397a6e573 (diff) | |
Refs #23968 -- Removed unnecessary lists, generators, and tuple calls.
Diffstat (limited to 'django')
26 files changed, 44 insertions, 45 deletions
diff --git a/django/apps/registry.py b/django/apps/registry.py index aff58db1c4..f522550d60 100644 --- a/django/apps/registry.py +++ b/django/apps/registry.py @@ -300,7 +300,7 @@ class Apps: This method is safe in the sense that it doesn't trigger any imports. """ available = set(available) - installed = set(app_config.name for app_config in self.get_app_configs()) + installed = {app_config.name for app_config in self.get_app_configs()} if not available.issubset(installed): raise ValueError( "Available apps isn't a subset of installed apps, extra apps: %s" diff --git a/django/contrib/admin/templatetags/admin_urls.py b/django/contrib/admin/templatetags/admin_urls.py index 097fbcf040..b926fe447a 100644 --- a/django/contrib/admin/templatetags/admin_urls.py +++ b/django/contrib/admin/templatetags/admin_urls.py @@ -25,7 +25,7 @@ def add_preserved_filters(context, url, popup=False, to_field=None): parsed_url = list(urlparse(url)) parsed_qs = dict(parse_qsl(parsed_url[4])) - merged_qs = dict() + merged_qs = {} if opts and preserved_filters: preserved_filters = dict(parse_qsl(preserved_filters)) diff --git a/django/contrib/auth/backends.py b/django/contrib/auth/backends.py index 7f5962b43c..52b80f8c49 100644 --- a/django/contrib/auth/backends.py +++ b/django/contrib/auth/backends.py @@ -54,7 +54,7 @@ class ModelBackend: else: perms = getattr(self, '_get_%s_permissions' % from_name)(user_obj) perms = perms.values_list('content_type__app_label', 'codename').order_by() - setattr(user_obj, perm_cache_name, set("%s.%s" % (ct, name) for ct, name in perms)) + setattr(user_obj, perm_cache_name, {"%s.%s" % (ct, name) for ct, name in perms}) return getattr(user_obj, perm_cache_name) def get_user_permissions(self, user_obj, obj=None): diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py index 922a6a3f28..36a2a7038f 100644 --- a/django/contrib/auth/management/__init__.py +++ b/django/contrib/auth/management/__init__.py @@ -50,7 +50,7 @@ def create_permissions(app_config, verbosity=2, interactive=True, using=DEFAULT_ # This will hold the permissions we're looking for as # (content_type, (codename, name)) - searched_perms = list() + searched_perms = [] # The codenames and ctypes that should exist. ctypes = set() for klass in app_config.get_models(): diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index fc269bbc73..e4e759502c 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -529,7 +529,7 @@ def create_generic_related_manager(superclass, rel): query = { '%s__pk' % self.content_type_field_name: self.content_type.id, - '%s__in' % self.object_id_field_name: set(obj._get_pk_val() for obj in instances) + '%s__in' % self.object_id_field_name: {obj._get_pk_val() for obj in instances} } # We (possibly) need to convert object IDs to the type of the diff --git a/django/contrib/flatpages/templatetags/flatpages.py b/django/contrib/flatpages/templatetags/flatpages.py index 09260ebaa8..985083d363 100644 --- a/django/contrib/flatpages/templatetags/flatpages.py +++ b/django/contrib/flatpages/templatetags/flatpages.py @@ -72,7 +72,7 @@ def get_flatpages(parser, token): bits = token.split_contents() syntax_message = ("%(tag_name)s expects a syntax of %(tag_name)s " "['url_starts_with'] [for user] as context_name" % - dict(tag_name=bits[0])) + {'tag_name': bits[0]}) # Must have at 3-6 bits in the tag if len(bits) >= 3 and len(bits) <= 6: diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 6e8211bdff..acc0613e6b 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -159,7 +159,7 @@ class MemcachedCache(BaseMemcachedCache): @property def _cache(self): if getattr(self, '_client', None) is None: - client_kwargs = dict(pickleProtocol=pickle.HIGHEST_PROTOCOL) + client_kwargs = {'pickleProtocol': pickle.HIGHEST_PROTOCOL} client_kwargs.update(self._options) self._client = self._lib.Client(self._servers, **client_kwargs) return self._client diff --git a/django/core/management/base.py b/django/core/management/base.py index 857c15fb60..61ce6ebec5 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -428,7 +428,7 @@ class BaseCommand: plan = executor.migration_plan(executor.loader.graph.leaf_nodes()) if plan: - apps_waiting_migration = sorted(set(migration.app_label for migration, backwards in plan)) + apps_waiting_migration = sorted({migration.app_label for migration, backwards in plan}) self.stdout.write( self.style.NOTICE( "\nYou have %(unpplied_migration_count)s unapplied migration(s). " diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py index 49679599a2..786957e86f 100644 --- a/django/core/management/commands/loaddata.py +++ b/django/core/management/commands/loaddata.py @@ -235,7 +235,7 @@ class Command(BaseCommand): '.'.join(ext for ext in combo if ext) for combo in product(databases, ser_fmts, cmp_fmts) ) - targets = set('.'.join((fixture_name, suffix)) for suffix in suffixes) + targets = {'.'.join((fixture_name, suffix)) for suffix in suffixes} fixture_files = [] for fixture_dir in fixture_dirs: diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py index 013b6035b7..45fce19b0f 100644 --- a/django/core/management/commands/makemigrations.py +++ b/django/core/management/commands/makemigrations.py @@ -78,7 +78,7 @@ class Command(BaseCommand): loader = MigrationLoader(None, ignore_no_migrations=True) # Raise an error if any migrations are applied before their dependencies. - consistency_check_labels = set(config.label for config in apps.get_app_configs()) + consistency_check_labels = {config.label for config in apps.get_app_configs()} # Non-default databases are only checked if database routers used. aliases_to_check = connections if settings.DATABASE_ROUTERS else [DEFAULT_DB_ALIAS] for alias in sorted(aliases_to_check): diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py index eb50026eab..e549b7200b 100644 --- a/django/core/management/commands/migrate.py +++ b/django/core/management/commands/migrate.py @@ -143,7 +143,7 @@ class Command(BaseCommand): if target_app_labels_only: self.stdout.write( self.style.MIGRATE_LABEL(" Apply all migrations: ") + - (", ".join(sorted(set(a for a, n in targets))) or "(none)") + (", ".join(sorted({a for a, n in targets})) or "(none)") ) else: if targets[0][1] is None: diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py index 7e338d690f..7e3163fbfc 100644 --- a/django/db/backends/base/schema.py +++ b/django/db/backends/base/schema.py @@ -324,8 +324,8 @@ class BaseDatabaseSchemaEditor: unique_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format. """ - olds = set(tuple(fields) for fields in old_unique_together) - news = set(tuple(fields) for fields in new_unique_together) + olds = {tuple(fields) for fields in old_unique_together} + news = {tuple(fields) for fields in new_unique_together} # Deleted uniques for fields in olds.difference(news): self._delete_composed_index(model, fields, {'unique': True}, self.sql_delete_unique) @@ -340,8 +340,8 @@ class BaseDatabaseSchemaEditor: index_togethers must be doubly-nested, not the single-nested ["foo", "bar"] format. """ - olds = set(tuple(fields) for fields in old_index_together) - news = set(tuple(fields) for fields in new_index_together) + olds = {tuple(fields) for fields in old_index_together} + news = {tuple(fields) for fields in new_index_together} # Deleted indexes for fields in olds.difference(news): self._delete_composed_index(model, fields, {'index': True}, self.sql_delete_index) diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index edc6331cb7..10d7c623f8 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -169,7 +169,7 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): 'indexes': indexes, 'apps': apps, } - meta = type("Meta", tuple(), meta_contents) + meta = type("Meta", (), meta_contents) body['Meta'] = meta body['__module__'] = model.__module__ diff --git a/django/db/migrations/autodetector.py b/django/db/migrations/autodetector.py index 3804cfd959..3a49e26c92 100644 --- a/django/db/migrations/autodetector.py +++ b/django/db/migrations/autodetector.py @@ -1065,14 +1065,14 @@ class MigrationAutodetector: old_model_name = self.renamed_models.get((app_label, model_name), model_name) old_model_state = self.from_state.models[app_label, old_model_name] new_model_state = self.to_state.models[app_label, model_name] - old_options = dict( - option for option in old_model_state.options.items() - if option[0] in AlterModelOptions.ALTER_OPTION_KEYS - ) - new_options = dict( - option for option in new_model_state.options.items() - if option[0] in AlterModelOptions.ALTER_OPTION_KEYS - ) + old_options = { + key: value for key, value in old_model_state.options.items() + if key in AlterModelOptions.ALTER_OPTION_KEYS + } + new_options = { + key: value for key, value in new_model_state.options.items() + if key in AlterModelOptions.ALTER_OPTION_KEYS + } if old_options != new_options: self.add_operation( app_label, diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py index 08cf6e314b..7daf8a7eec 100644 --- a/django/db/migrations/operations/models.py +++ b/django/db/migrations/operations/models.py @@ -496,7 +496,7 @@ class AlterUniqueTogether(FieldRelatedOptionOperation): def __init__(self, name, unique_together): unique_together = normalize_together(unique_together) - self.unique_together = set(tuple(cons) for cons in unique_together) + self.unique_together = {tuple(cons) for cons in unique_together} super().__init__(name) def deconstruct(self): @@ -550,7 +550,7 @@ class AlterIndexTogether(FieldRelatedOptionOperation): def __init__(self, name, index_together): index_together = normalize_together(index_together) - self.index_together = set(tuple(cons) for cons in index_together) + self.index_together = {tuple(cons) for cons in index_together} super().__init__(name) def deconstruct(self): diff --git a/django/db/migrations/recorder.py b/django/db/migrations/recorder.py index 1b4508ff85..dcc27d525c 100644 --- a/django/db/migrations/recorder.py +++ b/django/db/migrations/recorder.py @@ -55,7 +55,7 @@ class MigrationRecorder: def applied_migrations(self): """Return a set of (app, name) of applied migrations.""" self.ensure_schema() - return set(tuple(x) for x in self.migration_qs.values_list("app", "name")) + return {tuple(x) for x in self.migration_qs.values_list("app", "name")} def record_applied(self, app, name): """Record that a migration was applied.""" diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py index a4027ef6f1..0578badabe 100644 --- a/django/db/migrations/state.py +++ b/django/db/migrations/state.py @@ -559,7 +559,7 @@ class ModelState: # First, make a Meta object meta_contents = {'app_label': self.app_label, "apps": apps} meta_contents.update(self.options) - meta = type("Meta", tuple(), meta_contents) + meta = type("Meta", (), meta_contents) # Then, work out our bases try: bases = tuple( diff --git a/django/db/models/base.py b/django/db/models/base.py index 11887d4a9d..16c7d3636f 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1294,7 +1294,7 @@ class Model(metaclass=ModelBase): @classmethod def _check_id_field(cls): """Check if `id` field is a primary key.""" - fields = list(f for f in cls._meta.local_fields if f.name == 'id' and f != cls._meta.pk) + fields = [f for f in cls._meta.local_fields if f.name == 'id' and f != cls._meta.pk] # fields is empty or consists of the invalid "id" field if fields and not fields[0].primary_key and cls._meta.pk.name == 'id': return [ diff --git a/django/db/models/fields/related_descriptors.py b/django/db/models/fields/related_descriptors.py index 542cafb6bd..86da637f26 100644 --- a/django/db/models/fields/related_descriptors.py +++ b/django/db/models/fields/related_descriptors.py @@ -122,7 +122,7 @@ class ForwardManyToOneDescriptor: # The check for len(...) == 1 is a special case that allows the query # to be join-less and smaller. Refs #21760. if self.field.remote_field.is_hidden() or len(self.field.foreign_related_fields) == 1: - query = {'%s__in' % related_field.name: set(instance_attr(inst)[0] for inst in instances)} + query = {'%s__in' % related_field.name: {instance_attr(inst)[0] for inst in instances}} else: query = {'%s__in' % self.field.related_query_name(): instances} queryset = queryset.filter(**query) diff --git a/django/db/models/options.py b/django/db/models/options.py index d1439f7973..82d96b739c 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -20,7 +20,7 @@ from django.utils.translation import override PROXY_PARENTS = object() -EMPTY_RELATION_TREE = tuple() +EMPTY_RELATION_TREE = () IMMUTABLE_WARNING = ( "The return type of '%s' should never be mutated. If you want to manipulate this list " diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 39f40d604d..d53bd7758c 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1251,8 +1251,7 @@ class Query: # (Consider case where rel_a is LOUTER and rel_a__col=1 is added - if # rel_a doesn't produce any rows, then the whole condition must fail. # So, demotion is OK. - existing_inner = set( - (a for a in self.alias_map if self.alias_map[a].join_type == INNER)) + existing_inner = {a for a in self.alias_map if self.alias_map[a].join_type == INNER} clause, _ = self._add_q(q_object, self.used_aliases) if clause: self.where.add(clause, AND) @@ -1437,8 +1436,8 @@ class Query: for pos, info in enumerate(reversed(path)): if len(joins) == 1 or not info.direct: break - join_targets = set(t.column for t in info.join_field.foreign_related_fields) - cur_targets = set(t.column for t in targets) + join_targets = {t.column for t in info.join_field.foreign_related_fields} + cur_targets = {t.column for t in targets} if not cur_targets.issubset(join_targets): break targets_dict = {r[1].column: r[0] for r in info.join_field.related_fields if r[1].column in cur_targets} diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index 128d9ce80a..771661ba6a 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -47,10 +47,10 @@ class BoundField: id_ = self.field.widget.attrs.get('id') or self.auto_id attrs = {'id': id_} if id_ else {} attrs = self.build_widget_attrs(attrs) - return list( + return [ BoundWidget(self.field.widget, widget, self.form.renderer) for widget in self.field.widget.subwidgets(self.html_name, self.value(), attrs=attrs) - ) + ] def __bool__(self): # BoundField evaluates to True even if it doesn't have subwidgets. diff --git a/django/forms/fields.py b/django/forms/fields.py index d665606745..eb16f2c353 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -873,8 +873,8 @@ class MultipleChoiceField(ChoiceField): data = [] if len(initial) != len(data): return True - initial_set = set(str(value) for value in initial) - data_set = set(str(value) for value in data) + initial_set = {str(value) for value in initial} + data_set = {str(value) for value in data} return data_set != initial_set diff --git a/django/forms/models.py b/django/forms/models.py index f4c415ed4f..98b56392d0 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -1289,7 +1289,7 @@ class ModelMultipleChoiceField(ModelChoiceField): params={'pk': pk}, ) qs = self.queryset.filter(**{'%s__in' % key: value}) - pks = set(str(getattr(o, key)) for o in qs) + pks = {str(getattr(o, key)) for o in qs} for val in value: if str(val) not in pks: raise ValidationError( @@ -1313,8 +1313,8 @@ class ModelMultipleChoiceField(ModelChoiceField): data = [] if len(initial) != len(data): return True - initial_set = set(str(value) for value in self.prepare_value(initial)) - data_set = set(str(value) for value in data) + initial_set = {str(value) for value in self.prepare_value(initial)} + data_set = {str(value) for value in data} return data_set != initial_set diff --git a/django/utils/cache.py b/django/utils/cache.py index 7e7428f112..e8576b539f 100644 --- a/django/utils/cache.py +++ b/django/utils/cache.py @@ -287,7 +287,7 @@ def patch_vary_headers(response, newheaders): else: vary_headers = [] # Use .lower() here so we treat headers as case-insensitive. - existing_headers = set(header.lower() for header in vary_headers) + existing_headers = {header.lower() for header in vary_headers} additional_headers = [newheader for newheader in newheaders if newheader.lower() not in existing_headers] response['Vary'] = ', '.join(vary_headers + additional_headers) @@ -300,7 +300,7 @@ def has_vary_header(response, header_query): if not response.has_header('Vary'): return False vary_headers = cc_delim_re.split(response['Vary']) - existing_headers = set(header.lower() for header in vary_headers) + existing_headers = {header.lower() for header in vary_headers} return header_query.lower() in existing_headers diff --git a/django/views/i18n.py b/django/views/i18n.py index 71f8cd575e..9edf83e857 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -230,7 +230,7 @@ class JavaScriptCatalog(View): return self.render_to_response(context) def get_paths(self, packages): - allowable_packages = dict((app_config.name, app_config) for app_config in apps.get_app_configs()) + allowable_packages = {app_config.name: app_config for app_config in apps.get_app_configs()} app_configs = [allowable_packages[p] for p in packages if p in allowable_packages] # paths of requested packages return [os.path.join(app.path, 'locale') for app in app_configs] |
