Used OrderedDict.fromkeys() to initialize OrderedDict with None values.

This commit is contained in:
Sergey Fedoseev 2017-08-23 20:40:17 +05:00 committed by Tim Graham
parent 939d923e8e
commit fac74b84a3
3 changed files with 5 additions and 5 deletions

View File

@ -627,8 +627,8 @@ class ModelAdmin(BaseModelAdmin):
exclude = exclude or None
# Remove declared form fields which are in readonly_fields.
new_attrs = OrderedDict(
(f, None) for f in readonly_fields
new_attrs = OrderedDict.fromkeys(
f for f in readonly_fields
if f in self.form.declared_fields
)
form = type(self.form.__name__, (self.form,), new_attrs)

View File

@ -87,8 +87,8 @@ class Command(BaseCommand):
if len(app_labels) == 0:
if primary_keys:
raise CommandError("You can only use --pks option with one model")
app_list = OrderedDict(
(app_config, None) for app_config in apps.get_app_configs()
app_list = OrderedDict.fromkeys(
app_config for app_config in apps.get_app_configs()
if app_config.models_module is not None and app_config not in excluded_apps
)
else:

View File

@ -10,7 +10,7 @@ class OrderedSet:
"""
def __init__(self, iterable=None):
self.dict = OrderedDict(((x, None) for x in iterable) if iterable else [])
self.dict = OrderedDict.fromkeys(iterable or ())
def add(self, item):
self.dict[item] = None