Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f75805e

Browse files
committed
Issue21738: clarify usage of __new__ in Enum subclasses
1 parent 0081f23 commit f75805e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Doc/library/enum.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,7 @@ Avoids having to specify the value for each enumeration member::
586586

587587
The :meth:`__new__` method, if defined, is used during creation of the Enum
588588
members; it is then replaced by Enum's :meth:`__new__` which is used after
589-
class creation for lookup of existing members. Due to the way Enums are
590-
supposed to behave, there is no way to customize Enum's :meth:`__new__`.
589+
class creation for lookup of existing members.
591590

592591

593592
OrderedEnum
@@ -743,7 +742,11 @@ but not of the class::
743742
>>> dir(Planet.EARTH)
744743
['__class__', '__doc__', '__module__', 'name', 'surface_gravity', 'value']
745744

746-
A :meth:`__new__` method will only be used for the creation of the
747-
:class:`Enum` members -- after that it is replaced. This means if you wish to
748-
change how :class:`Enum` members are looked up you either have to write a
749-
helper function or a :func:`classmethod`.
745+
The :meth:`__new__` method will only be used for the creation of the
746+
:class:`Enum` members -- after that it is replaced. Any custom :meth:`__new__`
747+
method must create the object and set the :attr:`_value_` attribute
748+
appropriately.
749+
750+
If you wish to change how :class:`Enum` members are looked up you should either
751+
write a helper function or a :func:`classmethod` for the :class:`Enum`
752+
subclass.

0 commit comments

Comments
 (0)