Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f75805ed
Commit
f75805ed
authored
Sep 16, 2014
by
Ethan Furman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue21738: clarify usage of __new__ in Enum subclasses
parent
0081f23a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
Doc/library/enum.rst
Doc/library/enum.rst
+9
-6
No files found.
Doc/library/enum.rst
View file @
f75805ed
...
...
@@ -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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment