@@ -92,6 +92,11 @@ Module Contents
92
92
the bitwise operators without losing their :class: `IntFlag ` membership.
93
93
:class: `IntFlag ` members are also subclasses of :class: `int `. (`Notes `_)
94
94
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
+
95
100
:class: `EnumCheck `
96
101
97
102
An enumeration with the values ``CONTINUOUS ``, ``NAMED_FLAGS ``, and
@@ -132,9 +137,20 @@ Module Contents
132
137
133
138
Do not make ``obj `` a member. Can be used as a decorator.
134
139
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
+
135
151
136
152
.. 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 ``
138
154
139
155
---------------
140
156
@@ -573,6 +589,20 @@ Data Types
573
589
better support the *replacement of existing constants * use-case.
574
590
:meth: `__format__ ` was already :func: `int.__format__ ` for that same reason.
575
591
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
576
606
577
607
.. class :: EnumCheck
578
608
@@ -808,6 +838,22 @@ Utilities and Decorators
808
838
809
839
.. versionadded :: 3.11
810
840
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
+
811
857
---------------
812
858
813
859
Notes
0 commit comments