[Python-checkins] cpython (3.4): Issue21738: clarify usage of __new__ in Enum subclasses
ethan.furman
python-checkins at python.org
Wed Sep 17 04:14:35 CEST 2014
http://hg.python.org/cpython/rev/28c21f09719e
changeset: 92446:28c21f09719e
branch: 3.4
parent: 92444:4135f3929b35
user: Ethan Furman <ethan at stoneleaf.us>
date: Tue Sep 16 19:13:31 2014 -0700
summary:
Issue21738: clarify usage of __new__ in Enum subclasses
files:
Doc/library/enum.rst | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
--- a/Doc/library/enum.rst
+++ b/Doc/library/enum.rst
@@ -586,8 +586,7 @@
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 @@
>>> 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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list