summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2014-09-17 02:14:00 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2014-09-17 02:14:00 (GMT)
commit52351c7037ca2e98d56907815f69e6441fcc5071 (patch)
treee46d95cecb85cbcec2f0b66f323e77a123534b0b
parent6a8e0fbcfbd7b8778e88a80c96ea8df597dbc9f3 (diff)
parentf75805edb8d1399586bae6c12611705a4345b572 (diff)
downloadcpython-52351c7037ca2e98d56907815f69e6441fcc5071.zip
cpython-52351c7037ca2e98d56907815f69e6441fcc5071.tar.gz
cpython-52351c7037ca2e98d56907815f69e6441fcc5071.tar.bz2
Issue21738: clarify usage of __new__ in Enum subclasses
-rw-r--r--Doc/library/enum.rst15
1 files changed, 9 insertions, 6 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index acdcf7f..503d305 100644
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -586,8 +586,7 @@ Avoids having to specify the value for each enumeration member::
The :meth:`__new__` method, if defined, is used during creation of the Enum
members; it is then replaced by Enum's :meth:`__new__` which is used after
- class creation for lookup of existing members. Due to the way Enums are
- supposed to behave, there is no way to customize Enum's :meth:`__new__`.
+ class creation for lookup of existing members.
OrderedEnum
@@ -743,7 +742,11 @@ but not of the class::
>>> dir(Planet.EARTH)
['__class__', '__doc__', '__module__', 'name', 'surface_gravity', 'value']
-A :meth:`__new__` method will only be used for the creation of the
-:class:`Enum` members -- after that it is replaced. This means if you wish to
-change how :class:`Enum` members are looked up you either have to write a
-helper function or a :func:`classmethod`.
+The :meth:`__new__` method will only be used for the creation of the
+:class:`Enum` members -- after that it is replaced. Any custom :meth:`__new__`
+method must create the object and set the :attr:`_value_` attribute
+appropriately.
+
+If you wish to change how :class:`Enum` members are looked up you should either
+write a helper function or a :func:`classmethod` for the :class:`Enum`
+subclass.