diff --git a/pep-0435.txt b/pep-0435.txt index 4fafdd479..dccd4e3a5 100644 --- a/pep-0435.txt +++ b/pep-0435.txt @@ -213,8 +213,8 @@ Iterating over the members of an enum does not provide the aliases:: >>> list(Shape) [, , ] -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:: [, , , ] 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 =========