Skip to content

Commit

Permalink
pythongh-118310: Fix documentation for enum.Enum.__new__ (pythonGH-…
Browse files Browse the repository at this point in the history
…118311)

The provided example was incorrect:
- The example enum was missing the `int` mixin as implied by the context
- The value of `int('1a', 16)` was incorrectly given as 17
  (should be 26)
(cherry picked from commit 48e52fe)

Co-authored-by: Momo Eissenhauer <[email protected]>
  • Loading branch information
mmEissen authored and miss-islington committed May 7, 2024
1 parent 56c61cc commit 4a0b186
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,15 @@ Data Types
in the member assignment will be passed; e.g.

>>> from enum import Enum
>>> class MyIntEnum(Enum):
... SEVENTEEN = '1a', 16
>>> class MyIntEnum(int, Enum):
... TWENTYSIX = '1a', 16

results in the call ``int('1a', 16)`` and a value of ``17`` for the member.
results in the call ``int('1a', 16)`` and a value of ``26`` for the member.

.. note:: When writing a custom ``__new__``, do not use ``super().__new__`` --
call the appropriate ``__new__`` instead.
.. note::

When writing a custom ``__new__``, do not use ``super().__new__`` --
call the appropriate ``__new__`` instead.

.. method:: Enum.__repr__(self)

Expand Down

0 comments on commit 4a0b186

Please sign in to comment.