- The functional API gets a keyword-only `module` argument.
- Spell it 'mix-in' - Clarify "behavior only"
This commit is contained in:
parent
74f93fcf95
commit
b10b0848b2
17
pep-0435.txt
17
pep-0435.txt
|
@ -410,11 +410,12 @@ a ``StrEnum`` that mixes in ``str`` instead of ``int``.
|
|||
|
||||
Some rules:
|
||||
|
||||
1. When subclassing Enum, mixing types must appear before Enum itself in the
|
||||
sequence of bases.
|
||||
1. When subclassing Enum, mix-in types must appear before Enum itself in the
|
||||
sequence of bases, as in the ``IntEnum`` example above.
|
||||
2. While Enum can have members of any type, once you mix in an additional
|
||||
type, all the members must have values of that type, e.g. ``int`` above.
|
||||
This restriction does not apply to behavior-only mixins.
|
||||
This restriction does not apply to mix-ins which only add methods
|
||||
and don't specify another data type such as ``int`` or ``str``.
|
||||
|
||||
|
||||
Functional API
|
||||
|
@ -432,12 +433,12 @@ The ``Enum`` class is callable, providing the following functional API::
|
|||
>>> list(Animal)
|
||||
[<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. This argument
|
||||
can be the short name of the enum or a dotted-name including the
|
||||
module path to better support pickling. E.g.::
|
||||
The semantics of this API resemble ``namedtuple``. The first argument
|
||||
of the call to ``Enum`` is the name of the enumeration. To support
|
||||
pickling of these enums, the module name can be specified using the
|
||||
``module`` keyword-only argument. E.g.::
|
||||
|
||||
>>> Animals = Enum('animals.Animals', 'ant bee cat dog')
|
||||
>>> Animals = Enum('Animals', 'ant bee cat dog', module=__name__)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue