@@ -235,16 +235,30 @@ Data Types
235
235
>>> len(Color)
236
236
3
237
237
238
+ .. attribute :: EnumType.__members__
239
+
240
+ Returns a mapping of every enum name to its member, including aliases
241
+
238
242
.. method :: EnumType.__reversed__(cls)
239
243
240
244
Returns each member in *cls * in reverse definition order::
241
245
242
246
>>> list(reversed(Color))
243
247
[<Color.BLUE: 3>, <Color.GREEN: 2>, <Color.RED: 1>]
244
248
249
+ .. method :: EnumType._add_alias_
250
+
251
+ Adds a new name as an alias to an existing member. Raises a
252
+ :exc: `NameError ` if the name is already assigned to a different member.
253
+
254
+ .. method :: EnumType._add_value_alias_
255
+
256
+ Adds a new value as an alias to an existing member. Raises a
257
+ :exc: `ValueError ` if the value is already linked with a different member.
258
+
245
259
.. versionadded :: 3.11
246
260
247
- Before 3.11 ``enum `` used ``EnumMeta `` type , which is kept as an alias.
261
+ Before 3.11 ``EnumType `` was called ``EnumMeta ``, which is still available as an alias.
248
262
249
263
250
264
.. class :: Enum
@@ -323,7 +337,7 @@ Data Types
323
337
>>> PowersOfThree.SECOND.value
324
338
9
325
339
326
- .. method :: Enum.__init_subclass__(cls, **kwds)
340
+ .. method :: Enum.__init_subclass__(cls, \ **kwds)
327
341
328
342
A *classmethod * that is used to further configure subsequent subclasses.
329
343
By default, does nothing.
@@ -549,7 +563,7 @@ Data Types
549
563
550
564
.. method :: __invert__(self):
551
565
552
- Returns all the flags in *type(self) * that are not in self::
566
+ Returns all the flags in *type(self) * that are not in * self * ::
553
567
554
568
>>> ~white
555
569
<Color: 0>
@@ -769,37 +783,41 @@ Supported ``__dunder__`` names
769
783
:attr: `~EnumType.__members__ ` is a read-only ordered mapping of ``member_name ``:``member ``
770
784
items. It is only available on the class.
771
785
772
- :meth: `~object.__new__ `, if specified, must create and return the enum members; it is
773
- also a very good idea to set the member's :attr: `!_value_ ` appropriately. Once
774
- all the members are created it is no longer used.
786
+ :meth: `~object.__new__ `, if specified, must create and return the enum members;
787
+ it is also a very good idea to set the member's :attr: `!_value_ ` appropriately.
788
+ Once all the members are created it is no longer used.
775
789
776
790
777
791
Supported ``_sunder_ `` names
778
792
""""""""""""""""""""""""""""
779
793
780
- - ``_name_ `` -- name of the member
781
- - ``_value_ `` -- value of the member; can be set / modified in ``__new__ ``
782
-
783
- - ``_missing_ `` -- a lookup function used when a value is not found; may be
784
- overridden
785
- - ``_ignore_ `` -- a list of names, either as a :class: `list ` or a :class: `str `,
786
- that will not be transformed into members, and will be removed from the final
787
- class
788
- - ``_order_ `` -- used in Python 2/3 code to ensure member order is consistent
789
- (class attribute, removed during class creation)
790
- - ``_generate_next_value_ `` -- used to get an appropriate value for an enum
791
- member; may be overridden
794
+ - :meth: `~EnumType._add_alias_ ` -- adds a new name as an alias to an existing
795
+ member.
796
+ - :meth: `~EnumType._add_value_alias_ ` -- adds a new value as an alias to an
797
+ existing member.
798
+ - :attr: `~Enum._name_ ` -- name of the member
799
+ - :attr: `~Enum._value_ ` -- value of the member; can be set in ``__new__ ``
800
+ - :meth: `~Enum._missing_ ` -- a lookup function used when a value is not found;
801
+ may be overridden
802
+ - :attr: `~Enum._ignore_ ` -- a list of names, either as a :class: `list ` or a
803
+ :class: `str `, that will not be transformed into members, and will be removed
804
+ from the final class
805
+ - :attr: `~Enum._order_ ` -- used in Python 2/3 code to ensure member order is
806
+ consistent (class attribute, removed during class creation)
807
+ - :meth: `~Enum._generate_next_value_ ` -- used to get an appropriate value for
808
+ an enum member; may be overridden
792
809
793
810
.. note ::
794
811
795
- For standard :class: `Enum ` classes the next value chosen is the last value seen
796
- incremented by one.
812
+ For standard :class: `Enum ` classes the next value chosen is the highest
813
+ value seen incremented by one.
797
814
798
815
For :class: `Flag ` classes the next value chosen will be the next highest
799
- power-of-two, regardless of the last value seen .
816
+ power-of-two.
800
817
801
818
.. versionadded :: 3.6 ``_missing_``, ``_order_``, ``_generate_next_value_``
802
819
.. versionadded :: 3.7 ``_ignore_``
820
+ .. versionadded :: 3.13 ``_add_alias_``, ``_add_value_alias_``
803
821
804
822
---------------
805
823
0 commit comments