[docs] Code, test, and doc review for PEP-0435 Enum (issue 17947)

ethan at stoneleaf.us ethan at stoneleaf.us
Mon Jun 10 16:13:01 CEST 2013


http://bugs.python.org/review/17947/diff/8339/Doc/library/enum.rst
File Doc/library/enum.rst (right):

http://bugs.python.org/review/17947/diff/8339/Doc/library/enum.rst#newcode60
Doc/library/enum.rst:60: Enums also have a property that contains just
their item name::
Fixed this one and the other further down.

http://bugs.python.org/review/17947/diff/8339/Doc/library/enum.rst#newcode314
Doc/library/enum.rst:314: >>> Animals = Enum('Animals', 'ant bee cat
dog', module=__name__)
Moved, and reworded:

Pickling enums created with the functional API can be tricky as frame
stack
implementation details are used to try and figure out which module the
enumeration is being created in (e.g. it will fail if you use a utility
function in separate module, and also may not work on IronPython or
Jython).
The solution is to specify the module name explicitly as follows::

http://bugs.python.org/review/17947/diff/8339/Doc/library/enum.rst#newcode337
Doc/library/enum.rst:337: A variation of :class:`Enum` is proposed which
is also a subclass of
Done.

http://bugs.python.org/review/17947/diff/8339/Doc/library/enum.rst#newcode423
Doc/library/enum.rst:423: One frequent request is to not have to specify
values for enum members::
Major rewrite:

Interesting examples
====================

While :class:`Enum` and :class:`IntEnum` are expected to cover the
majority of
use-cases, they cannot cover them all.  Here are recipes for some
different
types of enumerations that can be used directly, or as examples for
creating
one's own.


AutoNumber
----------

Avoids having to specify the value for each enumeration member::

.
.
.

UniqueEnum
----------

Raises an error if a duplicate member name is found instead of creating
an
alias::

.
.
.

OrderedEnum
-----------

An ordered enumeration that is not based on :class:`IntEnum` and so
maintains
the normal :class:`Enum` invariants (such as not being comparable to
other
enumerations)::

.
.
.

Planet
------

If :meth:`__new__` or :meth:`__init__` is defined the value of the enum
member
will be passed to those methods::

http://bugs.python.org/review/17947/diff/8339/Lib/test/test_enum.py
File Lib/test/test_enum.py (right):

http://bugs.python.org/review/17947/diff/8339/Lib/test/test_enum.py#newcode474
Lib/test/test_enum.py:474: _reserved_ = 0
Removed.

http://bugs.python.org/review/17947/


More information about the docs mailing list