@@ -83,16 +83,23 @@ def __new__(metacls, name, bases, namespace, shape=None, **kwargs):
83
83
category = SyntaxWarning ,
84
84
stacklevel = 2 )
85
85
# Actually instantiate the enumeration class.
86
- cls = py_enum .EnumMeta .__new__ (metacls , name , bases , namespace , ** kwargs )
87
86
if shape is not None :
87
+ cls = py_enum .EnumMeta .__new__ (metacls , name , bases , namespace , ** kwargs )
88
88
# Shape is provided explicitly. Set the `_amaranth_shape_` attribute, and check that
89
89
# the values of every member can be cast to the provided shape without truncation.
90
90
cls ._amaranth_shape_ = shape
91
91
else :
92
92
# Shape is not provided explicitly. Behave the same as a standard enumeration;
93
93
# the lack of `_amaranth_shape_` attribute is used to emit a warning when such
94
94
# an enumeration is used in a concatenation.
95
- pass
95
+ bases = tuple (
96
+ py_enum .Enum if base is Enum else
97
+ py_enum .IntEnum if base is IntEnum else
98
+ py_enum .Flag if base is Flag else
99
+ py_enum .IntFlag if base is IntFlag else base
100
+ for base in bases
101
+ )
102
+ cls = py_enum .EnumMeta .__new__ (py_enum .EnumMeta , name , bases , namespace , ** kwargs )
96
103
return cls
97
104
98
105
def as_shape (cls ):
@@ -144,21 +151,28 @@ def const(cls, init):
144
151
return Const (member .value , cls .as_shape ())
145
152
146
153
147
- class Enum (py_enum .Enum , metaclass = EnumMeta ):
154
+ class Enum (py_enum .Enum ):
148
155
"""Subclass of the standard :class:`enum.Enum` that has :class:`EnumMeta` as
149
156
its metaclass."""
150
157
151
158
152
- class IntEnum (py_enum .IntEnum , metaclass = EnumMeta ):
159
+ class IntEnum (py_enum .IntEnum ):
153
160
"""Subclass of the standard :class:`enum.IntEnum` that has :class:`EnumMeta` as
154
161
its metaclass."""
155
162
156
163
157
- class Flag (py_enum .Flag , metaclass = EnumMeta ):
164
+ class Flag (py_enum .Flag ):
158
165
"""Subclass of the standard :class:`enum.Flag` that has :class:`EnumMeta` as
159
166
its metaclass."""
160
167
161
168
162
- class IntFlag (py_enum .IntFlag , metaclass = EnumMeta ):
169
+ class IntFlag (py_enum .IntFlag ):
163
170
"""Subclass of the standard :class:`enum.IntFlag` that has :class:`EnumMeta` as
164
171
its metaclass."""
172
+
173
+ # Fix up the metaclass after the fact: the metaclass __new__ requires these classes
174
+ # to already be present, and also would not install itself on them due to lack of shape.
175
+ Enum .__class__ = EnumMeta
176
+ IntEnum .__class__ = EnumMeta
177
+ Flag .__class__ = EnumMeta
178
+ IntFlag .__class__ = EnumMeta
0 commit comments