From 783afda70ad55e39f268c953997ec0f92ba37aee Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Mon, 23 Jan 2017 16:13:49 -0800 Subject: [PATCH] [1.11.x] Replaced dict() usage with dict literals. Literals are faster and more idiomatic. Backport of 0d74c41981687598d3fa0a7eb9712ce4c387ca19 from master --- django/forms/widgets.py | 20 +++++++------- django/test/runner.py | 10 +++---- tests/admin_views/tests.py | 42 ++++++++++++++++------------- tests/view_tests/tests/test_i18n.py | 14 +++++----- 4 files changed, 46 insertions(+), 40 deletions(-) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 0a170b01184..f50ddd52bad 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -608,16 +608,16 @@ class ChoiceWidget(Widget): option_attrs.update(self.checked_attribute) if 'id' in option_attrs: option_attrs['id'] = self.id_for_label(option_attrs['id'], index) - return dict( - name=name, - value=value, - label=label, - selected=selected, - index=index, - attrs=option_attrs, - type=self.input_type, - template_name=self.option_template_name, - ) + return { + 'name': name, + 'value': value, + 'label': label, + 'selected': selected, + 'index': index, + 'attrs': option_attrs, + 'type': self.input_type, + 'template_name': self.option_template_name, + } def get_context(self, name, value, attrs=None): context = super(ChoiceWidget, self).get_context(name, value, attrs) diff --git a/django/test/runner.py b/django/test/runner.py index 487ec7c682f..4dc8eb97f74 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -550,11 +550,11 @@ class DiscoverRunner(object): return DebugSQLTextTestResult if self.debug_sql else None def get_test_runner_kwargs(self): - return dict( - failfast=self.failfast, - resultclass=self.get_resultclass(), - verbosity=self.verbosity, - ) + return { + 'failfast': self.failfast, + 'resultclass': self.get_resultclass(), + 'verbosity': self.verbosity, + } def run_checks(self): # Checks are run after database creation since some checks require diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index c952a9ebf27..4f281bd01aa 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -588,24 +588,30 @@ class AdminViewBasicTest(AdminViewBasicTestCase): response = self.client.get(changelist_url) self.assertContains(response, '
') filters = { - 'chap__id__exact': dict( - values=[c.id for c in Chapter.objects.all()], - test=lambda obj, value: obj.chap.id == value), - 'chap__title': dict( - values=[c.title for c in Chapter.objects.all()], - test=lambda obj, value: obj.chap.title == value), - 'chap__book__id__exact': dict( - values=[b.id for b in Book.objects.all()], - test=lambda obj, value: obj.chap.book.id == value), - 'chap__book__name': dict( - values=[b.name for b in Book.objects.all()], - test=lambda obj, value: obj.chap.book.name == value), - 'chap__book__promo__id__exact': dict( - values=[p.id for p in Promo.objects.all()], - test=lambda obj, value: obj.chap.book.promo_set.filter(id=value).exists()), - 'chap__book__promo__name': dict( - values=[p.name for p in Promo.objects.all()], - test=lambda obj, value: obj.chap.book.promo_set.filter(name=value).exists()), + 'chap__id__exact': { + 'values': [c.id for c in Chapter.objects.all()], + 'test': lambda obj, value: obj.chap.id == value, + }, + 'chap__title': { + 'values': [c.title for c in Chapter.objects.all()], + 'test': lambda obj, value: obj.chap.title == value, + }, + 'chap__book__id__exact': { + 'values': [b.id for b in Book.objects.all()], + 'test': lambda obj, value: obj.chap.book.id == value, + }, + 'chap__book__name': { + 'values': [b.name for b in Book.objects.all()], + 'test': lambda obj, value: obj.chap.book.name == value, + }, + 'chap__book__promo__id__exact': { + 'values': [p.id for p in Promo.objects.all()], + 'test': lambda obj, value: obj.chap.book.promo_set.filter(id=value).exists(), + }, + 'chap__book__promo__name': { + 'values': [p.name for p in Promo.objects.all()], + 'test': lambda obj, value: obj.chap.book.promo_set.filter(name=value).exists(), + }, } for filter_path, params in filters.items(): for value in params['values']: diff --git a/tests/view_tests/tests/test_i18n.py b/tests/view_tests/tests/test_i18n.py index bde0ad42d48..e389f841353 100644 --- a/tests/view_tests/tests/test_i18n.py +++ b/tests/view_tests/tests/test_i18n.py @@ -141,13 +141,13 @@ class I18NTests(TestCase): def test_setlang_cookie(self): # we force saving language to a cookie rather than a session # by excluding session middleware and those which do require it - test_settings = dict( - MIDDLEWARE=['django.middleware.common.CommonMiddleware'], - LANGUAGE_COOKIE_NAME='mylanguage', - LANGUAGE_COOKIE_AGE=3600 * 7 * 2, - LANGUAGE_COOKIE_DOMAIN='.example.com', - LANGUAGE_COOKIE_PATH='/test/', - ) + test_settings = { + 'MIDDLEWARE': ['django.middleware.common.CommonMiddleware'], + 'LANGUAGE_COOKIE_NAME': 'mylanguage', + 'LANGUAGE_COOKIE_AGE': 3600 * 7 * 2, + 'LANGUAGE_COOKIE_DOMAIN': '.example.com', + 'LANGUAGE_COOKIE_PATH': '/test/', + } with self.settings(**test_settings): post_data = dict(language='pl', next='/views/') response = self.client.post('/i18n/setlang/', data=post_data)