@@ -194,7 +194,7 @@ Data Types
194
194
195
195
.. method :: EnumType.__getitem__(cls, name)
196
196
197
- Returns the Enum member in *cls * matching *name *, or raises an :exc: `KeyError `::
197
+ Returns the Enum member in *cls * matching *name *, or raises a :exc: `KeyError `::
198
198
199
199
>>> Color['BLUE']
200
200
<Color.BLUE: 3>
@@ -241,7 +241,7 @@ Data Types
241
241
242
242
.. note :: Enum member values
243
243
244
- Member values can be anything: :class: `int `, :class: `str `, etc.. If
244
+ Member values can be anything: :class: `int `, :class: `str `, etc. If
245
245
the exact value is unimportant you may use :class: `auto ` instances and an
246
246
appropriate value will be chosen for you. See :class: `auto ` for the
247
247
details.
@@ -255,7 +255,7 @@ Data Types
255
255
names will also be removed from the completed enumeration. See
256
256
:ref: `TimePeriod <enum-time-period >` for an example.
257
257
258
- .. method :: Enum.__call__(cls, value, names=None, \ *, module=None, qualname=None, type=None, start=1, boundary=None)
258
+ .. method :: Enum.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
259
259
260
260
This method is called in two different ways:
261
261
@@ -272,8 +272,8 @@ Data Types
272
272
:module: The name of the module the new Enum is created in.
273
273
:qualname: The actual location in the module where this Enum can be found.
274
274
:type: A mix-in type for the new Enum.
275
- :start: The first integer value for the Enum (used by :class: `auto `)
276
- :boundary: How to handle out-of-range values from bit operations (:class: `Flag ` only)
275
+ :start: The first integer value for the Enum (used by :class: `auto `).
276
+ :boundary: How to handle out-of-range values from bit operations (:class: `Flag ` only).
277
277
278
278
.. method :: Enum.__dir__(self)
279
279
@@ -315,7 +315,7 @@ Data Types
315
315
>>> PowersOfThree.SECOND.value
316
316
6
317
317
318
- .. method :: Enum.__init_subclass__(cls, \ **kwds)
318
+ .. method :: Enum.__init_subclass__(cls, **kwds)
319
319
320
320
A *classmethod * that is used to further configure subsequent subclasses.
321
321
By default, does nothing.
@@ -373,7 +373,7 @@ Data Types
373
373
.. method :: Enum.__format__(self)
374
374
375
375
Returns the string used for *format() * and *f-string * calls. By default,
376
- returns :meth: `__str__ ` returns , but can be overridden::
376
+ returns :meth: `__str__ ` return value , but can be overridden::
377
377
378
378
>>> class OtherStyle(Enum):
379
379
... ALTERNATE = auto()
@@ -552,11 +552,11 @@ Data Types
552
552
Using :class: `auto ` with :class: `Flag ` results in integers that are powers
553
553
of two, starting with ``1 ``.
554
554
555
- .. versionchanged :: 3.11 The *repr()* of zero-valued flags has changed. It
555
+ .. versionchanged :: 3.11 The *repr()* of zero-valued flags has changed. It
556
556
is now::
557
557
558
- >>> Color(0) # doctest: +SKIP
559
- <Color: 0>
558
+ >>> Color(0) # doctest: +SKIP
559
+ <Color: 0>
560
560
561
561
.. class :: IntFlag
562
562
@@ -600,7 +600,7 @@ Data Types
600
600
*replacement of existing constants * use-case. :meth: `~object.__format__ ` was
601
601
already :meth: `!int.__format__ ` for that same reason.
602
602
603
- Inversion of a :class: `!IntFlag ` now returns a positive value that is the
603
+ Inversion of an :class: `!IntFlag ` now returns a positive value that is the
604
604
union of all flags not in the given flag, rather than a negative value.
605
605
This matches the existing :class: `Flag ` behavior.
606
606
@@ -612,7 +612,7 @@ Data Types
612
612
* :meth: `!int.__str__ ` for :class: `IntEnum ` and :class: `IntFlag `
613
613
* :meth: `!str.__str__ ` for :class: `StrEnum `
614
614
615
- Inherit from :class: `!ReprEnum ` to keep the :class: `str() <str> / :func:`format `
615
+ Inherit from :class: `!ReprEnum ` to keep the :class: `str() <str> ` / :func: `format `
616
616
of the mixed-in data type instead of using the
617
617
:class: `Enum `-default :meth: `str() <Enum.__str__> `.
618
618
@@ -658,7 +658,7 @@ Data Types
658
658
.. attribute :: NAMED_FLAGS
659
659
660
660
Ensure that any flag groups/masks contain only named flags -- useful when
661
- values are specified instead of being generated by :func: `auto `
661
+ values are specified instead of being generated by :func: `auto `::
662
662
663
663
>>> from enum import Flag, verify, NAMED_FLAGS
664
664
>>> @verify(NAMED_FLAGS)
@@ -804,6 +804,11 @@ Utilities and Decorators
804
804
* ``THREE = [auto(), -3] `` will *not * work (``<auto instance>, -3 `` is used to
805
805
create the ``THREE `` enum member)
806
806
807
+ .. versionchanged :: 3.11.1
808
+
809
+ In prior versions, ``auto() `` had to be the only thing
810
+ on the assignment line to work properly.
811
+
807
812
``_generate_next_value_ `` can be overridden to customize the values used by
808
813
*auto *.
809
814
@@ -885,23 +890,23 @@ Notes
885
890
886
891
:class: `IntEnum `, :class: `StrEnum `, and :class: `IntFlag `
887
892
888
- These three enum types are designed to be drop-in replacements for existing
889
- integer- and string-based values; as such, they have extra limitations:
893
+ These three enum types are designed to be drop-in replacements for existing
894
+ integer- and string-based values; as such, they have extra limitations:
890
895
891
- - ``__str__ `` uses the value and not the name of the enum member
896
+ - ``__str__ `` uses the value and not the name of the enum member
892
897
893
- - ``__format__ ``, because it uses ``__str__ ``, will also use the value of
894
- the enum member instead of its name
898
+ - ``__format__ ``, because it uses ``__str__ ``, will also use the value of
899
+ the enum member instead of its name
895
900
896
- If you do not need/want those limitations, you can either create your own
897
- base class by mixing in the ``int `` or ``str `` type yourself::
901
+ If you do not need/want those limitations, you can either create your own
902
+ base class by mixing in the ``int `` or ``str `` type yourself::
898
903
899
- >>> from enum import Enum
900
- >>> class MyIntEnum(int, Enum):
901
- ... pass
904
+ >>> from enum import Enum
905
+ >>> class MyIntEnum(int, Enum):
906
+ ... pass
902
907
903
908
or you can reassign the appropriate :meth: `str `, etc., in your enum::
904
909
905
- >>> from enum import IntEnum
906
- >>> class MyIntEnum(IntEnum):
907
- ... __str__ = IntEnum.__str__
910
+ >>> from enum import IntEnum
911
+ >>> class MyIntEnum(IntEnum):
912
+ ... __str__ = IntEnum.__str__
0 commit comments