Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #30159 -- Removed obsolete use of OrderedDict with Python 3.6+. #10945

Merged
merged 1 commit into from Feb 6, 2019

Conversation

ngnpope
Copy link
Member

@ngnpope ngnpope commented Feb 5, 2019

Ticket #30159.

Follows on from #10894 (comment).

Use of OrderedDict remains in two places:

  • django.core.cache.backends.locmem -- uses OrderedDict.move_to_end().
  • django.core.serializers.pyyaml -- retain ability to serialize OrderedDict.

Some observations:

  • We no longer need DeclarativeFieldsMetaclass.__prepare__() as the class namespace is initialised as an empty ordered mapping.
  • We no longer need the object_pairs_hook parameter to json.loads() in ManifestFilesMixin.load_manifest() as dict is the default.
  • A workaround is currently required in django.core.serializers.pyyaml because dictionary items are sorted by key, see Allow to turn off sorting keys in Dumper yaml/pyyaml#143.
  • Query.annotations and Query.extra are simplified because it is no longer necessary to instantiate an OrderedDict lazily.
  • The unit test queries.tests.Queries1Tests.test_ticket2902 is obsolete and is removed.

(name, (func, name, desc))
for func, name, desc in actions
)
# Convert the actions into a dictionary keyed by name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that comment could be removed as the dict comprehension seems somewhat obvious.

@@ -35,6 +35,10 @@ def represent_ordered_dict(self, data):
DjangoSafeDumper.add_representer(decimal.Decimal, DjangoSafeDumper.represent_decimal)
DjangoSafeDumper.add_representer(collections.OrderedDict, DjangoSafeDumper.represent_ordered_dict)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would chop the blank line.

((COMPILED_REGEX_TYPE, RegexObject), RegexSerializer),
(uuid.UUID, UUIDSerializer),
])
_registry = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would restore the "some of these are order-dependent." comment that was removed in 7d3b389 as it may not be obvious without OrderedDict.

Dicts preserve order since Python 3.6.
@timgraham timgraham merged commit 24b82cd into django:master Feb 6, 2019
@ngnpope ngnpope deleted the ticket-30159 branch February 6, 2019 19:52
@ngnpope
Copy link
Member Author

ngnpope commented Feb 6, 2019

Thanks Tim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants