[Python-checkins] peps: Minor clean up of PEP 520.
eric.snow
python-checkins at python.org
Tue Jun 7 23:09:32 EDT 2016
https://hg.python.org/peps/rev/ea566ba82216
changeset: 6355:ea566ba82216
user: Eric Snow <ericsnowcurrently at gmail.com>
date: Tue Jun 07 20:09:27 2016 -0700
summary:
Minor clean up of PEP 520.
files:
pep-0520.txt | 22 ++++++++++++----------
1 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/pep-0520.txt b/pep-0520.txt
--- a/pep-0520.txt
+++ b/pep-0520.txt
@@ -16,8 +16,9 @@
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 @@
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 @@
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 @@
Alternatives
============
-type.__dict__ as OrderedDict
-----------------------------
+<class>.__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.
--
Repository URL: https://hg.python.org/peps
More information about the Python-checkins
mailing list