Replaced dict() usage with dict literals.

Literals are faster and more idiomatic.
This commit is contained in:
Jon Dufresne 2017-01-23 16:13:49 -08:00 committed by Tim Graham
parent d2e7d15b4c
commit 0d74c41981
4 changed files with 46 additions and 40 deletions

View File

@ -593,16 +593,16 @@ class ChoiceWidget(Widget):
option_attrs.update(self.checked_attribute) option_attrs.update(self.checked_attribute)
if 'id' in option_attrs: if 'id' in option_attrs:
option_attrs['id'] = self.id_for_label(option_attrs['id'], index) option_attrs['id'] = self.id_for_label(option_attrs['id'], index)
return dict( return {
name=name, 'name': name,
value=value, 'value': value,
label=label, 'label': label,
selected=selected, 'selected': selected,
index=index, 'index': index,
attrs=option_attrs, 'attrs': option_attrs,
type=self.input_type, 'type': self.input_type,
template_name=self.option_template_name, 'template_name': self.option_template_name,
) }
def get_context(self, name, value, attrs=None): def get_context(self, name, value, attrs=None):
context = super(ChoiceWidget, self).get_context(name, value, attrs) context = super(ChoiceWidget, self).get_context(name, value, attrs)

View File

@ -550,11 +550,11 @@ class DiscoverRunner:
return DebugSQLTextTestResult if self.debug_sql else None return DebugSQLTextTestResult if self.debug_sql else None
def get_test_runner_kwargs(self): def get_test_runner_kwargs(self):
return dict( return {
failfast=self.failfast, 'failfast': self.failfast,
resultclass=self.get_resultclass(), 'resultclass': self.get_resultclass(),
verbosity=self.verbosity, 'verbosity': self.verbosity,
) }
def run_checks(self): def run_checks(self):
# Checks are run after database creation since some checks require # Checks are run after database creation since some checks require

View File

@ -582,24 +582,30 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
response = self.client.get(changelist_url) response = self.client.get(changelist_url)
self.assertContains(response, '<div id="changelist-filter">') self.assertContains(response, '<div id="changelist-filter">')
filters = { filters = {
'chap__id__exact': dict( 'chap__id__exact': {
values=[c.id for c in Chapter.objects.all()], 'values': [c.id for c in Chapter.objects.all()],
test=lambda obj, value: obj.chap.id == value), 'test': lambda obj, value: obj.chap.id == value,
'chap__title': dict( },
values=[c.title for c in Chapter.objects.all()], 'chap__title': {
test=lambda obj, value: obj.chap.title == value), 'values': [c.title for c in Chapter.objects.all()],
'chap__book__id__exact': dict( 'test': lambda obj, value: obj.chap.title == value,
values=[b.id for b in Book.objects.all()], },
test=lambda obj, value: obj.chap.book.id == value), 'chap__book__id__exact': {
'chap__book__name': dict( 'values': [b.id for b in Book.objects.all()],
values=[b.name for b in Book.objects.all()], 'test': lambda obj, value: obj.chap.book.id == value,
test=lambda obj, value: obj.chap.book.name == value), },
'chap__book__promo__id__exact': dict( 'chap__book__name': {
values=[p.id for p in Promo.objects.all()], 'values': [b.name for b in Book.objects.all()],
test=lambda obj, value: obj.chap.book.promo_set.filter(id=value).exists()), 'test': lambda obj, value: obj.chap.book.name == value,
'chap__book__promo__name': dict( },
values=[p.name for p in Promo.objects.all()], 'chap__book__promo__id__exact': {
test=lambda obj, value: obj.chap.book.promo_set.filter(name=value).exists()), '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 filter_path, params in filters.items():
for value in params['values']: for value in params['values']:

View File

@ -134,13 +134,13 @@ class I18NTests(TestCase):
def test_setlang_cookie(self): def test_setlang_cookie(self):
# we force saving language to a cookie rather than a session # we force saving language to a cookie rather than a session
# by excluding session middleware and those which do require it # by excluding session middleware and those which do require it
test_settings = dict( test_settings = {
MIDDLEWARE=['django.middleware.common.CommonMiddleware'], 'MIDDLEWARE': ['django.middleware.common.CommonMiddleware'],
LANGUAGE_COOKIE_NAME='mylanguage', 'LANGUAGE_COOKIE_NAME': 'mylanguage',
LANGUAGE_COOKIE_AGE=3600 * 7 * 2, 'LANGUAGE_COOKIE_AGE': 3600 * 7 * 2,
LANGUAGE_COOKIE_DOMAIN='.example.com', 'LANGUAGE_COOKIE_DOMAIN': '.example.com',
LANGUAGE_COOKIE_PATH='/test/', 'LANGUAGE_COOKIE_PATH': '/test/',
) }
with self.settings(**test_settings): with self.settings(**test_settings):
post_data = dict(language='pl', next='/views/') post_data = dict(language='pl', next='/views/')
response = self.client.post('/i18n/setlang/', data=post_data) response = self.client.post('/i18n/setlang/', data=post_data)