A few PEP 435 clarifications.
This commit is contained in:
parent
939f5b14ff
commit
cc7de05c80
29
pep-0435.txt
29
pep-0435.txt
|
@ -213,8 +213,8 @@ Iterating over the members of an enum does not provide the aliases::
|
|||
>>> 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 @@ Equality comparisons are defined though::
|
|||
|
||||
>>> Color.blue == Color.red
|
||||
False
|
||||
>>> Color.blue != Color.red
|
||||
True
|
||||
>>> Color.blue == Color.blue
|
||||
True
|
||||
|
||||
|
@ -294,7 +296,7 @@ Then::
|
|||
|
||||
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 @@ The ``Enum`` class is callable, providing the following functional API::
|
|||
[<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 @@ References
|
|||
.. [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
|
||||
=========
|
||||
|
|
Loading…
Reference in New Issue