diff --git a/pep-0520.txt b/pep-0520.txt index 14138458d..376a29460 100644 --- a/pep-0520.txt +++ b/pep-0520.txt @@ -16,8 +16,9 @@ Abstract This PEP changes the default class definition namespace to ``OrderedDict``. Furthermore, the order in which the attributes are defined in each class -body will now be preserved in ``type.__definition_order__``. This allows -introspection of the original definition order, e.g. by class decorators. +body will now be preserved in the ``__definition_order__`` attribute of +the class. This allows introspection of the original definition order, +e.g. by class decorators. Note: just to be clear, this PEP is *not* about changing ``__dict__`` for classes to ``OrderedDict``. @@ -62,9 +63,9 @@ Specification 1. if ``__definition_order__`` is defined in the class body then the value is used as-is, though the attribute will still be read-only - 2. types that do not have a class definition (e.g. builtins) have + 2. classes that do not have a class definition (e.g. builtins) have their ``__definition_order__`` set to ``None`` - 3. types for which `__prepare__()`` returned something other than + 3. classes for which `__prepare__()`` returned something other than ``OrderedDict`` (or a subclass) have their ``__definition_order__`` set to ``None`` (except where #1 applies) @@ -78,8 +79,8 @@ The following code demonstrates roughly equivalent semantics:: ham = None eggs = 5 __definition_order__ = tuple(k for k in locals() - if (!k.startswith('__') or - !k.endswith('__'))) + if (not k.startswith('__') or + not k.endswith('__'))) Note that [pep487_] proposes a similar solution, albeit as part of a broader proposal. @@ -169,14 +170,15 @@ The implementation is found in the tracker. [impl_] Alternatives ============ -type.__dict__ as OrderedDict ----------------------------- +.__dict__ as OrderedDict +------------------------------- Instead of storing the definition order in ``__definition_order__``, the now-ordered definition namespace could be copied into a new -``OrderedDict``. This would mostly provide the same semantics. +``OrderedDict``. This would then be used as the mapping proxied as +``__dict__``. Doing so would mostly provide the same semantics. -However, using ``OrderedDict`` for ``type,__dict__`` would obscure the +However, using ``OrderedDict`` for ``__dict__`` would obscure the relationship with the definition namespace, making it less useful. Additionally, doing this would require significant changes to the semantics of the concrete ``dict`` C-API.