diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 0e275bc25a..a88c867d85 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -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) diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py index 11b6c8c244..b246cee238 100644 --- a/django/core/management/commands/dumpdata.py +++ b/django/core/management/commands/dumpdata.py @@ -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: diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index b42f674eb0..7713b08e8c 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -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