@@ -83,16 +83,23 @@ def __new__(metacls, name, bases, namespace, shape=None, **kwargs):
8383 category = SyntaxWarning ,
8484 stacklevel = 2 )
8585 # Actually instantiate the enumeration class.
86- cls = py_enum .EnumMeta .__new__ (metacls , name , bases , namespace , ** kwargs )
8786 if shape is not None :
87+ cls = py_enum .EnumMeta .__new__ (metacls , name , bases , namespace , ** kwargs )
8888 # Shape is provided explicitly. Set the `_amaranth_shape_` attribute, and check that
8989 # the values of every member can be cast to the provided shape without truncation.
9090 cls ._amaranth_shape_ = shape
9191 else :
9292 # Shape is not provided explicitly. Behave the same as a standard enumeration;
9393 # the lack of `_amaranth_shape_` attribute is used to emit a warning when such
9494 # 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 )
96103 return cls
97104
98105 def as_shape (cls ):
@@ -144,21 +151,28 @@ def const(cls, init):
144151 return Const (member .value , cls .as_shape ())
145152
146153
147- class Enum (py_enum .Enum , metaclass = EnumMeta ):
154+ class Enum (py_enum .Enum ):
148155 """Subclass of the standard :class:`enum.Enum` that has :class:`EnumMeta` as
149156 its metaclass."""
150157
151158
152- class IntEnum (py_enum .IntEnum , metaclass = EnumMeta ):
159+ class IntEnum (py_enum .IntEnum ):
153160 """Subclass of the standard :class:`enum.IntEnum` that has :class:`EnumMeta` as
154161 its metaclass."""
155162
156163
157- class Flag (py_enum .Flag , metaclass = EnumMeta ):
164+ class Flag (py_enum .Flag ):
158165 """Subclass of the standard :class:`enum.Flag` that has :class:`EnumMeta` as
159166 its metaclass."""
160167
161168
162- class IntFlag (py_enum .IntFlag , metaclass = EnumMeta ):
169+ class IntFlag (py_enum .IntFlag ):
163170 """Subclass of the standard :class:`enum.IntFlag` that has :class:`EnumMeta` as
164171 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