From 4c97101b1f0815a3f311fc77483b935fe62966bb Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 8 Aug 2012 07:33:15 -0700 Subject: [PATCH] remove a bunch of unnescesarry iterkeys() calls --- django/conf/__init__.py | 2 +- django/contrib/admin/options.py | 4 ++-- .../contrib/admin/templatetags/admin_list.py | 2 +- django/contrib/auth/admin.py | 2 +- django/contrib/auth/tests/forms.py | 2 +- django/contrib/formtools/wizard/views.py | 2 +- .../gis/db/backends/mysql/operations.py | 2 +- .../gis/db/backends/oracle/operations.py | 2 +- .../gis/db/backends/postgis/operations.py | 4 ++-- .../gis/db/backends/spatialite/operations.py | 2 +- django/contrib/gis/db/models/query.py | 2 +- django/contrib/gis/db/models/sql/compiler.py | 2 +- django/core/management/__init__.py | 2 +- django/core/serializers/__init__.py | 2 +- django/core/validators.py | 2 +- django/db/models/base.py | 4 ++-- django/db/models/deletion.py | 2 +- django/db/models/fields/__init__.py | 2 +- django/db/models/fields/related.py | 8 ++++---- django/db/models/options.py | 4 ++-- django/db/models/query.py | 18 +++++++++--------- django/db/models/sql/query.py | 6 +++--- django/template/defaulttags.py | 2 +- django/utils/datastructures.py | 2 +- django/utils/dictconfig.py | 2 +- 25 files changed, 42 insertions(+), 42 deletions(-) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 6325ccb1a9..e1c3fd1808 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -158,7 +158,7 @@ class UserSettingsHolder(BaseSettings): return getattr(self.default_settings, name) def __dir__(self): - return list(six.iterkeys(self.__dict__)) + dir(self.default_settings) + return list(self.__dict__) + dir(self.default_settings) # For Python < 2.6: __members__ = property(lambda self: self.__dir__()) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 7708050e6f..081d00121b 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -425,7 +425,7 @@ class ModelAdmin(BaseModelAdmin): if self.declared_fieldsets: return self.declared_fieldsets form = self.get_form(request, obj) - fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj)) + fields = list(form.base_fields) + list(self.get_readonly_fields(request, obj)) return [(None, {'fields': fields})] def get_form(self, request, obj=None, **kwargs): @@ -1415,7 +1415,7 @@ class InlineModelAdmin(BaseModelAdmin): if self.declared_fieldsets: return self.declared_fieldsets form = self.get_formset(request, obj).form - fields = list(six.iterkeys(form.base_fields)) + list(self.get_readonly_fields(request, obj)) + fields = list(form.base_fields) + list(self.get_readonly_fields(request, obj)) return [(None, {'fields': fields})] def queryset(self, request): diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index b8b64d032f..1873d44989 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -126,7 +126,7 @@ def result_headers(cl): if i in ordering_field_columns: sorted = True order_type = ordering_field_columns.get(i).lower() - sort_priority = list(six.iterkeys(ordering_field_columns)).index(i) + 1 + sort_priority = list(ordering_field_columns).index(i) + 1 th_classes.append('sorted %sending' % order_type) new_order_type = {'asc': 'desc', 'desc': 'asc'}[order_type] diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index cb09822f52..ccf940d16d 100644 --- a/django/contrib/auth/admin.py +++ b/django/contrib/auth/admin.py @@ -129,7 +129,7 @@ class UserAdmin(admin.ModelAdmin): else: form = self.change_password_form(user) - fieldsets = [(None, {'fields': list(six.iterkeys(form.base_fields))})] + fieldsets = [(None, {'fields': list(form.base_fields)})] adminForm = admin.helpers.AdminForm(form, fieldsets, {}) context = { diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py index f917ea2601..594b55c633 100644 --- a/django/contrib/auth/tests/forms.py +++ b/django/contrib/auth/tests/forms.py @@ -204,7 +204,7 @@ class PasswordChangeFormTest(TestCase): def test_field_order(self): # Regression test - check the order of fields: user = User.objects.get(username='testclient') - self.assertEqual(list(six.iterkeys(PasswordChangeForm(user, {}).fields)), + self.assertEqual(list(PasswordChangeForm(user, {}).fields), ['old_password', 'new_password1', 'new_password2']) diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index 741b7e52b6..ea41e86852 100644 --- a/django/contrib/formtools/wizard/views.py +++ b/django/contrib/formtools/wizard/views.py @@ -44,7 +44,7 @@ class StepsHelper(object): @property def all(self): "Returns the names of all steps/forms." - return list(six.iterkeys(self._wizard.get_form_list())) + return list(self._wizard.get_form_list()) @property def count(self): diff --git a/django/contrib/gis/db/backends/mysql/operations.py b/django/contrib/gis/db/backends/mysql/operations.py index 277b764810..7152f4682d 100644 --- a/django/contrib/gis/db/backends/mysql/operations.py +++ b/django/contrib/gis/db/backends/mysql/operations.py @@ -32,7 +32,7 @@ class MySQLOperations(DatabaseOperations, BaseSpatialOperations): 'within' : 'MBRWithin', } - gis_terms = dict([(term, None) for term in list(six.iterkeys(geometry_functions)) + ['isnull']]) + gis_terms = dict([(term, None) for term in list(geometry_functions) + ['isnull']]) def geo_db_type(self, f): return f.geom_type diff --git a/django/contrib/gis/db/backends/oracle/operations.py b/django/contrib/gis/db/backends/oracle/operations.py index 5db30e6fc6..392feb129b 100644 --- a/django/contrib/gis/db/backends/oracle/operations.py +++ b/django/contrib/gis/db/backends/oracle/operations.py @@ -128,7 +128,7 @@ class OracleOperations(DatabaseOperations, BaseSpatialOperations): geometry_functions.update(distance_functions) gis_terms = ['isnull'] - gis_terms += list(six.iterkeys(geometry_functions)) + gis_terms += list(geometry_functions) gis_terms = dict([(term, None) for term in gis_terms]) truncate_params = {'relate' : None} diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py index 92f8925a7d..434d8719cc 100644 --- a/django/contrib/gis/db/backends/postgis/operations.py +++ b/django/contrib/gis/db/backends/postgis/operations.py @@ -217,8 +217,8 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations): # Creating a dictionary lookup of all GIS terms for PostGIS. gis_terms = ['isnull'] - gis_terms += list(six.iterkeys(self.geometry_operators)) - gis_terms += list(six.iterkeys(self.geometry_functions)) + gis_terms += list(self.geometry_operators) + gis_terms += list(self.geometry_functions) self.gis_terms = dict([(term, None) for term in gis_terms]) self.area = prefix + 'Area' diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py index 31c98212e9..60fe0a8069 100644 --- a/django/contrib/gis/db/backends/spatialite/operations.py +++ b/django/contrib/gis/db/backends/spatialite/operations.py @@ -131,7 +131,7 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations): # Creating the GIS terms dictionary. gis_terms = ['isnull'] - gis_terms += list(six.iterkeys(self.geometry_functions)) + gis_terms += list(self.geometry_functions) self.gis_terms = dict([(term, None) for term in gis_terms]) if version >= (2, 4, 0): diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py index 6dc36d6ab8..cc61dfa4d2 100644 --- a/django/contrib/gis/db/models/query.py +++ b/django/contrib/gis/db/models/query.py @@ -26,7 +26,7 @@ class GeoQuerySet(QuerySet): flat = kwargs.pop('flat', False) if kwargs: raise TypeError('Unexpected keyword arguments to values_list: %s' - % (list(six.iterkeys(kwargs)),)) + % (list(kwargs),)) if flat and len(fields) > 1: raise TypeError("'flat' is not valid when values_list is called with more than one field.") return self._clone(klass=GeoValuesListQuerySet, setup=True, flat=flat, diff --git a/django/contrib/gis/db/models/sql/compiler.py b/django/contrib/gis/db/models/sql/compiler.py index 64d1a4d869..5c8d2647f7 100644 --- a/django/contrib/gis/db/models/sql/compiler.py +++ b/django/contrib/gis/db/models/sql/compiler.py @@ -171,7 +171,7 @@ class GeoSQLCompiler(compiler.SQLCompiler): objects. """ values = [] - aliases = list(six.iterkeys(self.query.extra_select)) + aliases = list(self.query.extra_select) # Have to set a starting row number offset that is used for # determining the correct starting row index -- needed for diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index e2f9798dcd..268cd63c38 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -295,7 +295,7 @@ class ManagementUtility(object): except IndexError: curr = '' - subcommands = list(six.iterkeys(get_commands())) + ['help'] + subcommands = list(get_commands()) + ['help'] options = [('--help', None)] # subcommand diff --git a/django/core/serializers/__init__.py b/django/core/serializers/__init__.py index 2d5e7624a4..cf7e66190f 100644 --- a/django/core/serializers/__init__.py +++ b/django/core/serializers/__init__.py @@ -76,7 +76,7 @@ def get_serializer(format): def get_serializer_formats(): if not _serializers: _load_serializers() - return list(six.iterkeys(_serializers)) + return list(_serializers) def get_public_serializer_formats(): if not _serializers: diff --git a/django/core/validators.py b/django/core/validators.py index fd5dfa28d6..456fa3cec5 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -138,7 +138,7 @@ def ip_address_validators(protocol, unpack_ipv4): return ip_address_validator_map[protocol.lower()] except KeyError: raise ValueError("The protocol '%s' is unknown. Supported: %s" - % (protocol, list(six.iterkeys(ip_address_validator_map)))) + % (protocol, list(ip_address_validator_map))) comma_separated_int_list_re = re.compile('^[\d,]+$') validate_comma_separated_integer_list = RegexValidator(comma_separated_int_list_re, _('Enter only digits separated by commas.'), 'invalid') diff --git a/django/db/models/base.py b/django/db/models/base.py index 35ae2231d6..569b8e876c 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -388,14 +388,14 @@ class Model(six.with_metaclass(ModelBase, object)): setattr(self, field.attname, val) if kwargs: - for prop in list(six.iterkeys(kwargs)): + for prop in list(kwargs): try: if isinstance(getattr(self.__class__, prop), property): setattr(self, prop, kwargs.pop(prop)) except AttributeError: pass if kwargs: - raise TypeError("'%s' is an invalid keyword argument for this function" % list(six.iterkeys(kwargs))[0]) + raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0]) super(Model, self).__init__() signals.post_init.send(sender=self.__class__, instance=self) diff --git a/django/db/models/deletion.py b/django/db/models/deletion.py index 2e5ed53e63..4449b75a81 100644 --- a/django/db/models/deletion.py +++ b/django/db/models/deletion.py @@ -207,7 +207,7 @@ class Collector(object): def sort(self): sorted_models = [] concrete_models = set() - models = list(six.iterkeys(self.data)) + models = list(self.data) while len(sorted_models) < len(models): found = False for model in models: diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index 3737a504bb..d07851bbf5 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -489,7 +489,7 @@ class Field(object): # Many of the subclass-specific formfield arguments (min_value, # max_value) don't apply for choice fields, so be sure to only pass # the values that TypedChoiceField will understand. - for k in list(six.iterkeys(kwargs)): + for k in list(kwargs): if k not in ('coerce', 'empty_value', 'choices', 'required', 'widget', 'label', 'initial', 'help_text', 'error_messages', 'show_hidden_initial'): diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index eaa62c6061..08cc0a747f 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -241,7 +241,7 @@ class SingleRelatedObjectDescriptor(object): rel_obj_attr = attrgetter(self.related.field.attname) instance_attr = lambda obj: obj._get_pk_val() instances_dict = dict((instance_attr(inst), inst) for inst in instances) - params = {'%s__pk__in' % self.related.field.name: list(six.iterkeys(instances_dict))} + params = {'%s__pk__in' % self.related.field.name: list(instances_dict)} qs = self.get_query_set(instance=instances[0]).filter(**params) # Since we're going to assign directly in the cache, # we must manage the reverse relation cache manually. @@ -335,9 +335,9 @@ class ReverseSingleRelatedObjectDescriptor(object): instance_attr = attrgetter(self.field.attname) instances_dict = dict((instance_attr(inst), inst) for inst in instances) if other_field.rel: - params = {'%s__pk__in' % self.field.rel.field_name: list(six.iterkeys(instances_dict))} + params = {'%s__pk__in' % self.field.rel.field_name: list(instances_dict)} else: - params = {'%s__in' % self.field.rel.field_name: list(six.iterkeys(instances_dict))} + params = {'%s__in' % self.field.rel.field_name: list(instances_dict)} qs = self.get_query_set(instance=instances[0]).filter(**params) # Since we're going to assign directly in the cache, # we must manage the reverse relation cache manually. @@ -488,7 +488,7 @@ class ForeignRelatedObjectsDescriptor(object): instance_attr = attrgetter(attname) instances_dict = dict((instance_attr(inst), inst) for inst in instances) db = self._db or router.db_for_read(self.model, instance=instances[0]) - query = {'%s__%s__in' % (rel_field.name, attname): list(six.iterkeys(instances_dict))} + query = {'%s__%s__in' % (rel_field.name, attname): list(instances_dict)} qs = super(RelatedManager, self).get_query_set().using(db).filter(**query) # Since we just bypassed this class' get_query_set(), we must manage # the reverse relation manually. diff --git a/django/db/models/options.py b/django/db/models/options.py index 239ad30b06..2e8ccb49ce 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -258,7 +258,7 @@ class Options(object): self._m2m_cache except AttributeError: self._fill_m2m_cache() - return list(six.iterkeys(self._m2m_cache)) + return list(self._m2m_cache) many_to_many = property(_many_to_many) def get_m2m_with_model(self): @@ -416,7 +416,7 @@ class Options(object): cache = self._fill_related_many_to_many_cache() if local_only: return [k for k, v in cache.items() if not v] - return list(six.iterkeys(cache)) + return list(cache) def get_all_related_m2m_objects_with_model(self): """ diff --git a/django/db/models/query.py b/django/db/models/query.py index 4441c1a4ef..e8d6ae2a7b 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -246,8 +246,8 @@ class QuerySet(object): requested = None max_depth = self.query.max_depth - extra_select = list(six.iterkeys(self.query.extra_select)) - aggregate_select = list(six.iterkeys(self.query.aggregate_select)) + extra_select = list(self.query.extra_select) + aggregate_select = list(self.query.aggregate_select) only_load = self.query.get_loaded_field_names() if not fill_cache: @@ -594,7 +594,7 @@ class QuerySet(object): flat = kwargs.pop('flat', False) if kwargs: raise TypeError('Unexpected keyword arguments to values_list: %s' - % (list(six.iterkeys(kwargs)),)) + % (list(kwargs),)) if flat and len(fields) > 1: raise TypeError("'flat' is not valid when values_list is called with more than one field.") return self._clone(klass=ValuesListQuerySet, setup=True, flat=flat, @@ -694,7 +694,7 @@ class QuerySet(object): depth = kwargs.pop('depth', 0) if kwargs: raise TypeError('Unexpected keyword arguments to select_related: %s' - % (list(six.iterkeys(kwargs)),)) + % (list(kwargs),)) obj = self._clone() if fields: if depth: @@ -752,7 +752,7 @@ class QuerySet(object): obj = self._clone() - obj._setup_aggregate_query(list(six.iterkeys(kwargs))) + obj._setup_aggregate_query(list(kwargs)) # Add the aggregates to the query for (alias, aggregate_expr) in kwargs.items(): @@ -967,9 +967,9 @@ class ValuesQuerySet(QuerySet): def iterator(self): # Purge any extra columns that haven't been explicitly asked for - extra_names = list(six.iterkeys(self.query.extra_select)) + extra_names = list(self.query.extra_select) field_names = self.field_names - aggregate_names = list(six.iterkeys(self.query.aggregate_select)) + aggregate_names = list(self.query.aggregate_select) names = extra_names + field_names + aggregate_names @@ -1098,9 +1098,9 @@ class ValuesListQuerySet(ValuesQuerySet): # When extra(select=...) or an annotation is involved, the extra # cols are always at the start of the row, and we need to reorder # the fields to match the order in self._fields. - extra_names = list(six.iterkeys(self.query.extra_select)) + extra_names = list(self.query.extra_select) field_names = self.field_names - aggregate_names = list(six.iterkeys(self.query.aggregate_select)) + aggregate_names = list(self.query.aggregate_select) names = extra_names + field_names + aggregate_names diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 69dda228bd..be257a5410 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1303,7 +1303,7 @@ class Query(object): field, model, direct, m2m = opts.get_field_by_name(f.name) break else: - names = opts.get_all_field_names() + list(six.iterkeys(self.aggregate_select)) + names = opts.get_all_field_names() + list(self.aggregate_select) raise FieldError("Cannot resolve keyword %r into field. " "Choices are: %s" % (name, ", ".join(names))) @@ -1661,8 +1661,8 @@ class Query(object): # from the model on which the lookup failed. raise else: - names = sorted(opts.get_all_field_names() + list(six.iterkeys(self.extra)) - + list(six.iterkeys(self.aggregate_select))) + names = sorted(opts.get_all_field_names() + list(self.extra) + + list(self.aggregate_select)) raise FieldError("Cannot resolve keyword %r into field. " "Choices are: %s" % (name, ", ".join(names))) self.remove_inherited_models() diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index dca47a3da8..14391f08e1 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -1189,7 +1189,7 @@ def templatetag(parser, token): if tag not in TemplateTagNode.mapping: raise TemplateSyntaxError("Invalid templatetag argument: '%s'." " Must be one of: %s" % - (tag, list(six.iterkeys(TemplateTagNode.mapping)))) + (tag, list(TemplateTagNode.mapping))) return TemplateTagNode(tag) @register.tag diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index bbd31ad36c..ad17573104 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -129,7 +129,7 @@ class SortedDict(dict): data = list(data) super(SortedDict, self).__init__(data) if isinstance(data, dict): - self.keyOrder = list(six.iterkeys(data)) + self.keyOrder = list(data) else: self.keyOrder = [] seen = set() diff --git a/django/utils/dictconfig.py b/django/utils/dictconfig.py index f8d6eebf89..c7b39819b5 100644 --- a/django/utils/dictconfig.py +++ b/django/utils/dictconfig.py @@ -363,7 +363,7 @@ class DictConfigurator(BaseConfigurator): #which were in the previous configuration but #which are not in the new configuration. root = logging.root - existing = list(six.iterkeys(root.manager.loggerDict)) + existing = list(root.manager.loggerDict) #The list needs to be sorted so that we can #avoid disabling child loggers of explicitly #named loggers. With a sorted list it is easier