Removed uneeded generator expressions and list comprehensions.

This commit is contained in:
Sergey Fedoseev 2019-02-09 19:18:48 +05:00 committed by Tim Graham
parent b1a2ad6925
commit 1933e56eca
9 changed files with 16 additions and 16 deletions

View File

@ -116,7 +116,7 @@ def ogrinspect(*args, **kwargs):
Note: Call the _ogrinspect() helper to do the heavy lifting.
"""
return '\n'.join(s for s in _ogrinspect(*args, **kwargs))
return '\n'.join(_ogrinspect(*args, **kwargs))
def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=None,

View File

@ -107,7 +107,7 @@ class DatabaseOperations(BaseDatabaseOperations):
except ValueError:
sql = field_name
else:
format_str = ''.join([f for f in format[:i]] + [f for f in format_def[i:]])
format_str = ''.join(format[:i] + format_def[i:])
sql = "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % (field_name, format_str)
return sql

View File

@ -160,7 +160,7 @@ class BaseForm:
"Key '%s' not found in '%s'. Choices are: %s." % (
name,
self.__class__.__name__,
', '.join(sorted(f for f in self.fields)),
', '.join(sorted(self.fields)),
)
)
if name not in self._bound_fields_cache:

View File

@ -72,7 +72,7 @@ class Element:
return self.children == element.children
def __hash__(self):
return hash((self.name, *(a for a in self.attributes)))
return hash((self.name, *self.attributes))
def _count(self, element, count=True):
if not isinstance(element, str):

View File

@ -156,14 +156,14 @@ class CharFieldTests(SimpleTestCase):
self.display = display
def __iter__(self):
return (x for x in [self.value, self.display])
return iter((self.value, self.display))
def __len__(self):
return 2
class Things:
def __iter__(self):
return (x for x in [ThingItem(1, 2), ThingItem(3, 4)])
return iter((ThingItem(1, 2), ThingItem(3, 4)))
class ThingWithIterableChoices(models.Model):
thing = models.CharField(max_length=100, blank=True, choices=Things())

View File

@ -531,7 +531,7 @@ class LookupTests(TestCase):
self.assertQuerysetEqual(Article.objects.filter(headline__startswith='Article').none(), [])
self.assertEqual(Article.objects.none().count(), 0)
self.assertEqual(Article.objects.none().update(headline="This should not take effect"), 0)
self.assertQuerysetEqual([article for article in Article.objects.none().iterator()], [])
self.assertQuerysetEqual(Article.objects.none().iterator(), [])
def test_in(self):
# using __in with an empty list should return an empty query set

View File

@ -844,8 +844,8 @@ class BaseEmailBackendTests(HeadersCheckMixin):
def test_send_many(self):
email1 = EmailMessage('Subject', 'Content1', 'from@example.com', ['to@example.com'])
email2 = EmailMessage('Subject', 'Content2', 'from@example.com', ['to@example.com'])
# send_messages() may take a list or a generator.
emails_lists = ([email1, email2], (email for email in [email1, email2]))
# send_messages() may take a list or an iterator.
emails_lists = ([email1, email2], iter((email1, email2)))
for emails_list in emails_lists:
num_sent = mail.get_connection().send_messages(emails_list)
self.assertEqual(num_sent, 2)

View File

@ -1935,9 +1935,9 @@ class RawQueriesTests(TestCase):
class GeneratorExpressionTests(SimpleTestCase):
def test_ticket10432(self):
# Using an empty generator expression as the rvalue for an "__in"
# Using an empty iterator as the rvalue for an "__in"
# lookup is legal.
self.assertCountEqual(Note.objects.filter(pk__in=(x for x in ())), [])
self.assertCountEqual(Note.objects.filter(pk__in=iter(())), [])
class ComparisonTests(TestCase):

View File

@ -77,17 +77,17 @@ class SimpleTemplateResponseTest(SimpleTestCase):
self.assertFalse(response.is_rendered)
def iteration():
for x in response:
pass
with self.assertRaises(ContentNotRenderedError):
list(response)
msg = 'The response content must be rendered before it can be iterated over.'
with self.assertRaisesMessage(ContentNotRenderedError, msg):
iteration()
self.assertFalse(response.is_rendered)
def test_iteration_rendered(self):
# iteration works for rendered responses
response = self._response().render()
res = [x for x in response]
self.assertEqual(res, [b'foo'])
self.assertEqual(list(response), [b'foo'])
def test_content_access_unrendered(self):
# unrendered response raises an exception when content is accessed