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. 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, 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: except ValueError:
sql = field_name sql = field_name
else: 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) sql = "CAST(DATE_FORMAT(%s, '%s') AS DATETIME)" % (field_name, format_str)
return sql return sql

View File

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

View File

@ -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, *(a for a in self.attributes))) return hash((self.name, *self.attributes))
def _count(self, element, count=True): def _count(self, element, count=True):
if not isinstance(element, str): if not isinstance(element, str):

View File

@ -156,14 +156,14 @@ class CharFieldTests(SimpleTestCase):
self.display = display self.display = display
def __iter__(self): def __iter__(self):
return (x for x in [self.value, self.display]) return iter((self.value, self.display))
def __len__(self): def __len__(self):
return 2 return 2
class Things: class Things:
def __iter__(self): 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): class ThingWithIterableChoices(models.Model):
thing = models.CharField(max_length=100, blank=True, choices=Things()) 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.assertQuerysetEqual(Article.objects.filter(headline__startswith='Article').none(), [])
self.assertEqual(Article.objects.none().count(), 0) self.assertEqual(Article.objects.none().count(), 0)
self.assertEqual(Article.objects.none().update(headline="This should not take effect"), 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): def test_in(self):
# using __in with an empty list should return an empty query set # 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): def test_send_many(self):
email1 = EmailMessage('Subject', 'Content1', 'from@example.com', ['to@example.com']) email1 = EmailMessage('Subject', 'Content1', 'from@example.com', ['to@example.com'])
email2 = EmailMessage('Subject', 'Content2', '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. # send_messages() may take a list or an iterator.
emails_lists = ([email1, email2], (email for email in [email1, email2])) emails_lists = ([email1, email2], iter((email1, email2)))
for emails_list in emails_lists: for emails_list in emails_lists:
num_sent = mail.get_connection().send_messages(emails_list) num_sent = mail.get_connection().send_messages(emails_list)
self.assertEqual(num_sent, 2) self.assertEqual(num_sent, 2)

View File

@ -1935,9 +1935,9 @@ class RawQueriesTests(TestCase):
class GeneratorExpressionTests(SimpleTestCase): class GeneratorExpressionTests(SimpleTestCase):
def test_ticket10432(self): 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. # 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): class ComparisonTests(TestCase):

View File

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