From 1933e56eca1ad17de7dd133bfb7cbee9858a75a3 Mon Sep 17 00:00:00 2001 From: Sergey Fedoseev Date: Sat, 9 Feb 2019 19:18:48 +0500 Subject: [PATCH] Removed uneeded generator expressions and list comprehensions. --- django/contrib/gis/utils/ogrinspect.py | 2 +- django/db/backends/mysql/operations.py | 2 +- django/forms/forms.py | 2 +- django/test/html.py | 2 +- tests/invalid_models_tests/test_ordinary_fields.py | 4 ++-- tests/lookup/tests.py | 2 +- tests/mail/tests.py | 4 ++-- tests/queries/tests.py | 4 ++-- tests/template_tests/test_response.py | 10 +++++----- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/django/contrib/gis/utils/ogrinspect.py b/django/contrib/gis/utils/ogrinspect.py index f04974f80dd..8c83fd5a43f 100644 --- a/django/contrib/gis/utils/ogrinspect.py +++ b/django/contrib/gis/utils/ogrinspect.py @@ -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, diff --git a/django/db/backends/mysql/operations.py b/django/db/backends/mysql/operations.py index 43f4f748d4e..50f85e06217 100644 --- a/django/db/backends/mysql/operations.py +++ b/django/db/backends/mysql/operations.py @@ -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 diff --git a/django/forms/forms.py b/django/forms/forms.py index 0c49a94432b..dd562099abc 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -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: diff --git a/django/test/html.py b/django/test/html.py index 3b55b528611..8b064529b0f 100644 --- a/django/test/html.py +++ b/django/test/html.py @@ -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): diff --git a/tests/invalid_models_tests/test_ordinary_fields.py b/tests/invalid_models_tests/test_ordinary_fields.py index 9c7cf7f88c5..a106ab175a7 100644 --- a/tests/invalid_models_tests/test_ordinary_fields.py +++ b/tests/invalid_models_tests/test_ordinary_fields.py @@ -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()) diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py index 3d68c04ea0e..666fadf262f 100644 --- a/tests/lookup/tests.py +++ b/tests/lookup/tests.py @@ -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 diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 029d332c427..9d8d21c3e71 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -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) diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 60e42433158..8128deca8b8 100644 --- a/tests/queries/tests.py +++ b/tests/queries/tests.py @@ -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): diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py index b0d66dc8097..9fcc0a9c7cb 100644 --- a/tests/template_tests/test_response.py +++ b/tests/template_tests/test_response.py @@ -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