Skip to content

Commit 35d0d48

Browse files
committed
Docs: Move Enum functions and add examples
When the `Enum` functions `_add_alias_` and `_add_value_alias_` were added in de6bca9, the documentation for them was done under `EnumType` instead of `Enum`. This change moves them to the docs of the `Enum` class and adds an example for each function.
1 parent acefb97 commit 35d0d48

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

Doc/howto/enum.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,9 +990,9 @@ Supported ``_sunder_`` names
990990
from the final class
991991
- :meth:`~Enum._generate_next_value_` -- used to get an appropriate value for
992992
an enum member; may be overridden
993-
- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing
993+
- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing
994994
member.
995-
- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an
995+
- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an
996996
existing member. See `MultiValueEnum`_ for an example.
997997

998998
.. note::

Doc/library/enum.rst

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,6 @@ Data Types
251251
>>> list(reversed(Color))
252252
[<Color.BLUE: 3>, <Color.GREEN: 2>, <Color.RED: 1>]
253253

254-
.. method:: EnumType._add_alias_
255-
256-
Adds a new name as an alias to an existing member. Raises a
257-
:exc:`NameError` if the name is already assigned to a different member.
258-
259-
.. method:: EnumType._add_value_alias_
260-
261-
Adds a new value as an alias to an existing member. Raises a
262-
:exc:`ValueError` if the value is already linked with a different member.
263-
264254
.. versionadded:: 3.11
265255

266256
Before 3.11 ``EnumType`` was called ``EnumMeta``, which is still available as an alias.
@@ -470,6 +460,30 @@ Data Types
470460

471461
.. versionchanged:: 3.12 Added :ref:`enum-dataclass-support`
472462

463+
.. method:: Enum._add_alias_
464+
465+
Adds a new name as an alias to an existing member::
466+
467+
>>> Color._add_alias_(Color.RED, "ERROR")
468+
>>> Color.ERROR
469+
<Color.RED: 1>
470+
471+
Raises a :exc:`NameError` if the name is already assigned to a different member.
472+
473+
.. versionadded:: 3.13
474+
475+
.. method:: Enum._add_value_alias_
476+
477+
Adds a new value as an alias to an existing member::
478+
479+
>>> Color._add_value_alias_(Color.RED, 42)
480+
>>> Color(42)
481+
<Color.RED: 1>
482+
483+
Raises a :exc:`ValueError` if the value is already linked with a different member.
484+
485+
.. versionadded:: 3.13
486+
473487

474488
.. class:: IntEnum
475489

@@ -864,9 +878,9 @@ Once all the members are created it is no longer used.
864878
Supported ``_sunder_`` names
865879
""""""""""""""""""""""""""""
866880

867-
- :meth:`~EnumType._add_alias_` -- adds a new name as an alias to an existing
881+
- :meth:`~Enum._add_alias_` -- adds a new name as an alias to an existing
868882
member.
869-
- :meth:`~EnumType._add_value_alias_` -- adds a new value as an alias to an
883+
- :meth:`~Enum._add_value_alias_` -- adds a new value as an alias to an
870884
existing member.
871885
- :attr:`~Enum._name_` -- name of the member
872886
- :attr:`~Enum._value_` -- value of the member; can be set in ``__new__``

0 commit comments

Comments
 (0)