Skip to content

Commit 3e95ffc

Browse files
gh-98298: [Enum] document ReprEnum, global_enum, and show_flag_values (GH-98455)
Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent a5ff80c commit 3e95ffc

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

Doc/library/enum.rst

+47-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ Module Contents
9292
the bitwise operators without losing their :class:`IntFlag` membership.
9393
:class:`IntFlag` members are also subclasses of :class:`int`. (`Notes`_)
9494

95+
:class:`ReprEnum`
96+
97+
Used by :class:`IntEnum`, :class:`StrEnum`, and :class:`IntFlag`
98+
to keep the :class:`str() <str>` of the mixed-in type.
99+
95100
:class:`EnumCheck`
96101

97102
An enumeration with the values ``CONTINUOUS``, ``NAMED_FLAGS``, and
@@ -132,9 +137,20 @@ Module Contents
132137

133138
Do not make ``obj`` a member. Can be used as a decorator.
134139

140+
:func:`global_enum`
141+
142+
Modify the :class:`str() <str>` and :func:`repr` of an enum
143+
to show its members as belonging to the module instead of its class.
144+
Should only be used if the enum members will be exported to the
145+
module global namespace.
146+
147+
:func:`show_flag_values`
148+
149+
Return a list of all power-of-two integers contained in a flag.
150+
135151

136152
.. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto``
137-
.. versionadded:: 3.11 ``StrEnum``, ``EnumCheck``, ``FlagBoundary``, ``property``, ``member``, ``nonmember``
153+
.. versionadded:: 3.11 ``StrEnum``, ``EnumCheck``, ``ReprEnum``, ``FlagBoundary``, ``property``, ``member``, ``nonmember``, ``global_enum``, ``show_flag_values``
138154

139155
---------------
140156

@@ -573,6 +589,20 @@ Data Types
573589
better support the *replacement of existing constants* use-case.
574590
:meth:`__format__` was already :func:`int.__format__` for that same reason.
575591

592+
.. class:: ReprEnum
593+
594+
:class:`!ReprEum` uses the :meth:`repr() <Enum.__repr__>` of :class:`Enum`,
595+
but the :class:`str() <str>` of the mixed-in data type:
596+
597+
* :meth:`!int.__str__` for :class:`IntEnum` and :class:`IntFlag`
598+
* :meth:`!str.__str__` for :class:`StrEnum`
599+
600+
Inherit from :class:`!ReprEnum` to keep the :class:`str() <str> / :func:`format`
601+
of the mixed-in data type instead of using the
602+
:class:`Enum`-default :meth:`str() <Enum.__str__>`.
603+
604+
605+
.. versionadded:: 3.11
576606

577607
.. class:: EnumCheck
578608

@@ -808,6 +838,22 @@ Utilities and Decorators
808838

809839
.. versionadded:: 3.11
810840

841+
.. decorator:: global_enum
842+
843+
A decorator to change the :class:`str() <str>` and :func:`repr` of an enum
844+
to show its members as belonging to the module instead of its class.
845+
Should only be used when the enum members are exported
846+
to the module global namespace (see :class:`re.RegexFlag` for an example).
847+
848+
849+
.. versionadded:: 3.11
850+
851+
.. function:: show_flag_values(value)
852+
853+
Return a list of all power-of-two integers contained in a flag *value*.
854+
855+
.. versionadded:: 3.11
856+
811857
---------------
812858

813859
Notes

0 commit comments

Comments
 (0)