[Python-checkins] peps: A few PEP 435 clarifications.
barry.warsaw
python-checkins at python.org
Mon May 6 22:15:44 CEST 2013
http://hg.python.org/peps/rev/1af9bc06972a
changeset: 4876:1af9bc06972a
user: Barry Warsaw <barry at python.org>
date: Mon May 06 16:15:38 2013 -0400
summary:
A few PEP 435 clarifications.
files:
pep-0435.txt | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/pep-0435.txt b/pep-0435.txt
--- a/pep-0435.txt
+++ b/pep-0435.txt
@@ -213,8 +213,8 @@
>>> list(Shape)
[<Shape.square: 2>, <Shape.diamond: 1>, <Shape.circle: 3>]
-If access to aliases is required for some reason, use the special attribute
-``__aliases__``::
+The special attribute ``__aliases__`` contains a list of all enum
+member aliases, by name::
>>> Shape.__aliases__
['alias_for_square']
@@ -244,6 +244,8 @@
>>> Color.blue == Color.red
False
+ >>> Color.blue != Color.red
+ True
>>> Color.blue == Color.blue
True
@@ -294,7 +296,7 @@
The rules for what is allowed are as follows: all attributes defined within an
enumeration will become members of this enumeration, with the exception of
-*__dunder__* names and descriptors; methods are descriptors too.
+*__dunder__* names and descriptors [9]_; methods are descriptors too.
Restricted subclassing of enumerations
@@ -418,13 +420,19 @@
[<Animal.ant: 1>, <Animal.bee: 2>, <Animal.cat: 3>, <Animal.dog: 4>]
The semantics of this API resemble ``namedtuple``. The first argument of
-the call to ``Enum`` is the name of the enumeration. The second argument is
-a source of enumeration member names. It can be a whitespace-separated string
-of names, a sequence of names or a sequence of 2-tuples with key/value pairs.
-The last option enables assigning arbitrary values to enumerations; the others
-auto-assign increasing integers starting with 1. A new class derived from
-``Enum`` is returned. In other words, the above assignment to ``Animal`` is
-equivalent to::
+the call to ``Enum`` is the name of the enumeration. This argument
+can be the short name of the enum or a dotted-name including the
+module path to better support pickling. E.g.::
+
+ >>> Animals = Enum('animals.Animals', 'ant bee cat dog')
+
+The second argument is the *source* of enumeration member names. It can be a
+whitespace-separated string of names, a sequence of names, a sequence of
+2-tuples with key/value pairs, or a mapping (e.g. dictionary) of names to
+values. The last two options enable assigning arbitrary values to
+enumerations; the others auto-assign increasing integers starting with 1. A
+new class derived from ``Enum`` is returned. In other words, the above
+assignment to ``Animal`` is equivalent to::
>>> class Animals(Enum):
... ant = 1
@@ -570,6 +578,7 @@
.. [6] http://mail.python.org/pipermail/python-dev/2013-April/125716.html
.. [7] http://mail.python.org/pipermail/python-dev/2013-May/125859.html
.. [8] http://pythonhosted.org/flufl.enum/
+.. [9] http://docs.python.org/3/howto/descriptor.html
Copyright
=========
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list