summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2019-02-05 11:22:08 +0000
committerTim Graham <timograham@gmail.com>2019-02-06 13:48:39 -0500
commit24b82cd201e21060fbc02117dc16d1702877a1f3 (patch)
tree7d36db9251700d0abf8fbf69399c8abc7fd9026a /django/core
parent21bb71ef0dcb86798edb0d8b21138bcc4b947590 (diff)
Fixed #30159 -- Removed unneeded use of OrderedDict.
Dicts preserve order since Python 3.6.
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management/__init__.py6
-rw-r--r--django/core/management/commands/dumpdata.py5
-rw-r--r--django/core/management/commands/inspectdb.py5
-rw-r--r--django/core/management/commands/migrate.py7
-rw-r--r--django/core/serializers/python.py5
-rw-r--r--django/core/serializers/pyyaml.py3
6 files changed, 15 insertions, 16 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index e0c924bdac..b8f47fa4a4 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -2,7 +2,7 @@ import functools
import os
import pkgutil
import sys
-from collections import OrderedDict, defaultdict
+from collections import defaultdict
from difflib import get_close_matches
from importlib import import_module
@@ -339,8 +339,8 @@ class ManagementUtility:
# The exception will be raised later in the child process
# started by the autoreloader. Pretend it didn't happen by
# loading an empty list of applications.
- apps.all_models = defaultdict(OrderedDict)
- apps.app_configs = OrderedDict()
+ apps.all_models = defaultdict(dict)
+ apps.app_configs = {}
apps.apps_ready = apps.models_ready = apps.ready = True
# Remove options not compatible with the built-in runserver
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index 31df5ac244..ce936c5459 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -1,5 +1,4 @@
import warnings
-from collections import OrderedDict
from django.apps import apps
from django.core import serializers
@@ -87,14 +86,14 @@ class Command(BaseCommand):
if not app_labels:
if primary_keys:
raise CommandError("You can only use --pks option with one model")
- app_list = OrderedDict.fromkeys(
+ app_list = dict.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:
if len(app_labels) > 1 and primary_keys:
raise CommandError("You can only use --pks option with one model")
- app_list = OrderedDict()
+ app_list = {}
for label in app_labels:
try:
app_label, model_label = label.split('.')
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 92f010a064..92c2035877 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -1,6 +1,5 @@
import keyword
import re
-from collections import OrderedDict
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS, connections
@@ -98,7 +97,7 @@ class Command(BaseCommand):
column_to_field_name = {} # Maps column names to names of model fields
for row in table_description:
comment_notes = [] # Holds Field notes, to be displayed in a Python comment.
- extra_params = OrderedDict() # Holds Field parameters such as 'db_column'.
+ extra_params = {} # Holds Field parameters such as 'db_column'.
column_name = row.name
is_relation = column_name in relations
@@ -232,7 +231,7 @@ class Command(BaseCommand):
description, this routine will return the given field type name, as
well as any additional keyword parameters and notes for the field.
"""
- field_params = OrderedDict()
+ field_params = {}
field_notes = []
try:
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index c2d0c16816..551804a72e 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -1,5 +1,4 @@
import time
-from collections import OrderedDict
from importlib import import_module
from django.apps import apps
@@ -314,10 +313,10 @@ class Command(BaseCommand):
(opts.auto_created and converter(opts.auto_created._meta.db_table) in tables)
)
- manifest = OrderedDict(
- (app_name, list(filter(model_installed, model_list)))
+ manifest = {
+ app_name: list(filter(model_installed, model_list))
for app_name, model_list in all_models
- )
+ }
# Create the tables for each model
if self.verbosity >= 1:
diff --git a/django/core/serializers/python.py b/django/core/serializers/python.py
index 08739c98fc..5a5d8a7036 100644
--- a/django/core/serializers/python.py
+++ b/django/core/serializers/python.py
@@ -3,7 +3,6 @@ A Python "serializer". Doesn't do much serializing per se -- just converts to
and from basic Python data types (lists, dicts, strings, etc.). Useful as a basis for
other serializers.
"""
-from collections import OrderedDict
from django.apps import apps
from django.core.serializers import base
@@ -26,14 +25,14 @@ class Serializer(base.Serializer):
pass
def start_object(self, obj):
- self._current = OrderedDict()
+ self._current = {}
def end_object(self, obj):
self.objects.append(self.get_dump_object(obj))
self._current = None
def get_dump_object(self, obj):
- data = OrderedDict([('model', str(obj._meta))])
+ data = {'model': str(obj._meta)}
if not self.use_natural_primary_keys or not hasattr(obj, 'natural_key'):
data["pk"] = self._value_from_field(obj, obj._meta.pk)
data['fields'] = self._current
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
index ed3d391d51..778c933584 100644
--- a/django/core/serializers/pyyaml.py
+++ b/django/core/serializers/pyyaml.py
@@ -34,6 +34,9 @@ class DjangoSafeDumper(SafeDumper):
DjangoSafeDumper.add_representer(decimal.Decimal, DjangoSafeDumper.represent_decimal)
DjangoSafeDumper.add_representer(collections.OrderedDict, DjangoSafeDumper.represent_ordered_dict)
+# Workaround to represent dictionaries in insertion order.
+# See https://github.com/yaml/pyyaml/pull/143.
+DjangoSafeDumper.add_representer(dict, DjangoSafeDumper.represent_ordered_dict)
class Serializer(PythonSerializer):