14
14
del _member
15
15
16
16
17
- class EnumMeta (ShapeCastable , py_enum .EnumMeta ):
18
- """Subclass of the standard :class:`enum.EnumMeta ` that implements the :class:`ShapeCastable`
17
+ class EnumType (ShapeCastable , py_enum .EnumMeta ):
18
+ """Subclass of the standard :class:`enum.EnumType ` that implements the :class:`ShapeCastable`
19
19
protocol.
20
20
21
21
This metaclass provides the :meth:`as_shape` method, making its instances
22
22
:ref:`shape-like <lang-shapelike>`, and accepts a ``shape=`` keyword argument
23
23
to specify a shape explicitly. Other than this, it acts the same as the standard
24
- :class:`enum.EnumMeta ` class; if the ``shape=`` argument is not specified and
24
+ :class:`enum.EnumType ` class; if the ``shape=`` argument is not specified and
25
25
:meth:`as_shape` is never called, it places no restrictions on the enumeration class
26
26
or the values of its members.
27
27
@@ -180,32 +180,37 @@ def _value_repr(cls, value):
180
180
yield Repr (FormatEnum (cls ), value )
181
181
182
182
183
+ # In 3.11, Python renamed EnumMeta to EnumType. Like Python itself, we support both for
184
+ # compatibility.
185
+ EnumMeta = EnumType
186
+
187
+
183
188
class Enum (py_enum .Enum ):
184
- """Subclass of the standard :class:`enum.Enum` that has :class:`EnumMeta ` as
189
+ """Subclass of the standard :class:`enum.Enum` that has :class:`EnumType ` as
185
190
its metaclass and :class:`EnumView` as its view class."""
186
191
187
192
188
193
class IntEnum (py_enum .IntEnum ):
189
- """Subclass of the standard :class:`enum.IntEnum` that has :class:`EnumMeta ` as
194
+ """Subclass of the standard :class:`enum.IntEnum` that has :class:`EnumType ` as
190
195
its metaclass."""
191
196
192
197
193
198
class Flag (py_enum .Flag ):
194
- """Subclass of the standard :class:`enum.Flag` that has :class:`EnumMeta ` as
199
+ """Subclass of the standard :class:`enum.Flag` that has :class:`EnumType ` as
195
200
its metaclass and :class:`FlagView` as its view class."""
196
201
197
202
198
203
class IntFlag (py_enum .IntFlag ):
199
- """Subclass of the standard :class:`enum.IntFlag` that has :class:`EnumMeta ` as
204
+ """Subclass of the standard :class:`enum.IntFlag` that has :class:`EnumType ` as
200
205
its metaclass."""
201
206
202
207
203
208
# Fix up the metaclass after the fact: the metaclass __new__ requires these classes
204
209
# to already be present, and also would not install itself on them due to lack of shape.
205
- Enum .__class__ = EnumMeta
206
- IntEnum .__class__ = EnumMeta
207
- Flag .__class__ = EnumMeta
208
- IntFlag .__class__ = EnumMeta
210
+ Enum .__class__ = EnumType
211
+ IntEnum .__class__ = EnumType
212
+ Flag .__class__ = EnumType
213
+ IntFlag .__class__ = EnumType
209
214
210
215
211
216
class EnumView (ValueCastable ):
@@ -219,7 +224,7 @@ def __init__(self, enum, target):
219
224
"""Constructs a view with the given enum type and target
220
225
(a :ref:`value-like <lang-valuelike>`).
221
226
"""
222
- if not isinstance (enum , EnumMeta ) or not hasattr (enum , "_amaranth_shape_" ):
227
+ if not isinstance (enum , EnumType ) or not hasattr (enum , "_amaranth_shape_" ):
223
228
raise TypeError (f"EnumView type must be an enum with shape, not { enum !r} " )
224
229
try :
225
230
cast_target = Value .cast (target )
0 commit comments