@@ -175,6 +175,10 @@ Data Types
175
175
final *enum *, as well as creating the enum members, properly handling
176
176
duplicates, providing iteration over the enum class, etc.
177
177
178
+ .. versionadded :: 3.11
179
+
180
+ Before 3.11 ``EnumType `` was called ``EnumMeta ``, which is still available as an alias.
181
+
178
182
.. method :: EnumType.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
179
183
180
184
This method is called in two different ways:
@@ -206,7 +210,7 @@ Data Types
206
210
>>> Color.RED.value in Color
207
211
True
208
212
209
- .. versionchanged :: 3.12
213
+ .. versionchanged :: 3.12
210
214
211
215
Before Python 3.12, a ``TypeError `` is raised if a
212
216
non-Enum-member is used in a containment check.
@@ -251,20 +255,6 @@ Data Types
251
255
>>> list(reversed(Color))
252
256
[<Color.BLUE: 3>, <Color.GREEN: 2>, <Color.RED: 1>]
253
257
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
-
264
- .. versionadded :: 3.11
265
-
266
- Before 3.11 ``EnumType `` was called ``EnumMeta ``, which is still available as an alias.
267
-
268
258
269
259
.. class :: Enum
270
260
@@ -470,6 +460,30 @@ Data Types
470
460
471
461
.. versionchanged :: 3.12 Added :ref:`enum-dataclass-support`
472
462
463
+ .. method :: Enum._add_alias_
464
+
465
+ Adds a new name as an alias to an existing member::
466
+
467
+ >>> Color.RED._add_alias_("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.RED._add_value_alias_(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
+
473
487
474
488
.. class :: IntEnum
475
489
@@ -879,10 +893,6 @@ Once all the members are created it is no longer used.
879
893
Supported ``_sunder_ `` names
880
894
""""""""""""""""""""""""""""
881
895
882
- - :meth: `~EnumType._add_alias_ ` -- adds a new name as an alias to an existing
883
- member.
884
- - :meth: `~EnumType._add_value_alias_ ` -- adds a new value as an alias to an
885
- existing member.
886
896
- :attr: `~Enum._name_ ` -- name of the member
887
897
- :attr: `~Enum._value_ ` -- value of the member; can be set in ``__new__ ``
888
898
- :meth: `~Enum._missing_ ` -- a lookup function used when a value is not found;
@@ -903,6 +913,11 @@ Supported ``_sunder_`` names
903
913
For :class: `Flag ` classes the next value chosen will be the next highest
904
914
power-of-two.
905
915
916
+ - :meth: `~Enum._add_alias_ ` -- adds a new name as an alias to an existing
917
+ member.
918
+ - :meth: `~Enum._add_value_alias_ ` -- adds a new value as an alias to an
919
+ existing member.
920
+
906
921
- While ``_sunder_ `` names are generally reserved for the further development
907
922
of the :class: `Enum ` class and can not be used, some are explicitly allowed:
908
923
0 commit comments