@@ -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
@@ -580,6 +596,20 @@ Data Types
580
596
better support the *replacement of existing constants * use-case.
581
597
:meth: `__format__ ` was already :func: `int.__format__ ` for that same reason.
582
598
599
+ .. class :: ReprEnum
600
+
601
+ :class: `!ReprEum ` uses the :meth: `repr() <Enum.__repr__> ` of :class: `Enum `,
602
+ but the :class: `str() <str> ` of the mixed-in data type:
603
+
604
+ * :meth: `!int.__str__ ` for :class: `IntEnum ` and :class: `IntFlag `
605
+ * :meth: `!str.__str__ ` for :class: `StrEnum `
606
+
607
+ Inherit from :class: `!ReprEnum ` to keep the :class: `str() <str> / :func:`format `
608
+ of the mixed-in data type instead of using the
609
+ :class: `Enum `-default :meth: `str() <Enum.__str__> `.
610
+
611
+
612
+ .. versionadded :: 3.11
583
613
584
614
.. class :: EnumCheck
585
615
@@ -815,6 +845,22 @@ Utilities and Decorators
815
845
816
846
.. versionadded :: 3.11
817
847
848
+ .. decorator :: global_enum
849
+
850
+ A decorator to change the :class: `str() <str> ` and :func: `repr ` of an enum
851
+ to show its members as belonging to the module instead of its class.
852
+ Should only be used when the enum members are exported
853
+ to the module global namespace (see :class: `re.RegexFlag ` for an example).
854
+
855
+
856
+ .. versionadded :: 3.11
857
+
858
+ .. function :: show_flag_values(value)
859
+
860
+ Return a list of all power-of-two integers contained in a flag *value *.
861
+
862
+ .. versionadded :: 3.11
863
+
818
864
---------------
819
865
820
866
Notes
0 commit comments