From f2b93b509c174ba5e2c82fc4e88537bad0996577 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Thu, 24 Aug 2017 01:48:29 +0500 Subject: [PATCH] Removed unneeded iter() calls. A few of these were unnecessarily added in 2b281cc35ed9d997614ca3c416928d7fabfef1ad. --- django/contrib/admin/sites.py | 2 +- django/contrib/gis/geos/collections.py | 2 +- django/contrib/gis/geos/mutable_list.py | 5 ++--- django/db/models/options.py | 2 +- django/http/request.py | 2 +- django/template/base.py | 2 +- django/views/i18n.py | 2 +- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index fcce8dba11..e68dfa1e8b 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -169,7 +169,7 @@ class AdminSite: """ Get all the enabled actions as an iterable of (name, func). """ - return iter(self._actions.items()) + return self._actions.items() @property def empty_value_display(self): diff --git a/django/contrib/gis/geos/collections.py b/django/contrib/gis/geos/collections.py index b8055d49f1..cea286d439 100644 --- a/django/contrib/gis/geos/collections.py +++ b/django/contrib/gis/geos/collections.py @@ -34,7 +34,7 @@ class GeometryCollection(GEOSGeometry): self._check_allowed(init_geoms) # Creating the geometry pointer array. - collection = self._create_collection(len(init_geoms), iter(init_geoms)) + collection = self._create_collection(len(init_geoms), init_geoms) super().__init__(collection, **kwargs) def __iter__(self): diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py index e151a3cffe..90fcc6d587 100644 --- a/django/contrib/gis/geos/mutable_list.py +++ b/django/contrib/gis/geos/mutable_list.py @@ -252,14 +252,13 @@ class ListMixin: def _set_slice(self, index, values): "Assign values to a slice of the object" try: - iter(values) + valueList = list(values) except TypeError: raise TypeError('can only assign an iterable to a slice') - self._check_allowed(values) + self._check_allowed(valueList) origLen = len(self) - valueList = list(values) start, stop, step = index.indices(origLen) # CAREFUL: index.step and step are not the same! diff --git a/django/db/models/options.py b/django/db/models/options.py index 9ed2915edb..3a4a33e7f9 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -51,7 +51,7 @@ def normalize_together(option_together): return () if not isinstance(option_together, (tuple, list)): raise TypeError - first_element = next(iter(option_together)) + first_element = option_together[0] if not isinstance(first_element, (tuple, list)): option_together = (option_together,) # Normalize everything to tuples diff --git a/django/http/request.py b/django/http/request.py index 17771f7ef6..28eae377a9 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -345,7 +345,7 @@ class HttpRequest: yield from self def readlines(self): - return list(iter(self)) + return list(self) class QueryDict(MultiValueDict): diff --git a/django/template/base.py b/django/template/base.py index 9ceba80dae..6572eae8ab 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -320,7 +320,7 @@ class Token: def split_contents(self): split = [] - bits = iter(smart_split(self.contents)) + bits = smart_split(self.contents) for bit in bits: # Handle translation-marked template pieces if bit.startswith(('_("', "_('")): diff --git a/django/views/i18n.py b/django/views/i18n.py index 9a16a78368..e121d3038a 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -279,7 +279,7 @@ class JavaScriptCatalog(View): trans_cat = self.translation._catalog trans_fallback_cat = self.translation._fallback._catalog if self.translation._fallback else {} seen_keys = set() - for key, value in itertools.chain(iter(trans_cat.items()), iter(trans_fallback_cat.items())): + for key, value in itertools.chain(trans_cat.items(), trans_fallback_cat.items()): if key == '' or key in seen_keys: continue if isinstance(key, str):