◐ Shell
clean mode source ↗

bpo-32506: Change dataclasses from OrderedDict to plain dict. by ericvsmith · Pull Request #5131 · python/cpython

@@ -1,7 +1,6 @@ import sys import types from copy import deepcopy import collections import inspect
__all__ = ['dataclass', Expand Down Expand Up @@ -448,11 +447,11 @@ def _set_attribute(cls, name, value):

def _process_class(cls, repr, eq, order, hash, init, frozen): # Use an OrderedDict because: # - Order matters! # - Derived class fields overwrite base class fields, but the # order is defined by the base class, which is found first. fields = collections.OrderedDict() # Now that dicts retain insertion order, there's no reason to use # an ordered dict. I am leveraging that ordering here, because # derived class fields overwrite base class fields, but the order # is defined by the base class, which is found first. fields = {}
# Find our base classes in reverse MRO order, and exclude # ourselves. In reversed order so that more derived classes Expand Down Expand Up @@ -612,7 +611,8 @@ def fields(class_or_instance): except AttributeError: raise TypeError('must be called with a dataclass type or instance')
# Exclude pseudo-fields. # Exclude pseudo-fields. Note that fields is sorted by insertion # order, so the order of the tuple is as the fields were defined. return tuple(f for f in fields.values() if f._field_type is _FIELD)

Expand Down Expand Up @@ -735,7 +735,7 @@ class C(Base): # Copy namespace since we're going to mutate it. namespace = namespace.copy()
anns = collections.OrderedDict() anns = {} for item in fields: if isinstance(item, str): name = item Expand Down