Skip to content

Commit 0435142

Browse files
committed
proliferate __new__ warning
1 parent 561dac5 commit 0435142

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Doc/howto/enum.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,19 @@ Note: if your enumeration defines :meth:`__new__` and/or :meth:`__init__` then
430430
any value(s) given to the enum member will be passed into those methods.
431431
See `Planet`_ for an example.
432432

433+
.. note::
434+
435+
The :meth:`__new__` method, if defined, is used during creation of the Enum
436+
members; it is then replaced by Enum's :meth:`__new__` which is used after
437+
class creation for lookup of existing members.
438+
439+
.. warning::
440+
441+
*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
442+
that is found; instead, use the data type directly -- e.g.::
443+
444+
obj = int.__new__(cls, value)
445+
433446

434447
Restricted Enum subclassing
435448
---------------------------
@@ -927,6 +940,11 @@ want one of them to be the value::
927940
>>> print(Coordinate(3))
928941
Coordinate.VY
929942

943+
.. warning::
944+
945+
*Do not* call ``super().__new__()``, as the lookup-only ``__new__`` is the one
946+
that is found; instead, use the data type directly.
947+
930948

931949
Finer Points
932950
^^^^^^^^^^^^

0 commit comments

Comments
 (0)