Skip to content

Commit 00699f7

Browse files
wanda-phiwhitequark
authored andcommitted
lib.enum: allow using functional syntax for enum creation.
Fixes #910.
1 parent dacbd9d commit 00699f7

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

amaranth/lib/enum.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def as_shape(cls):
118118
# replacement for `enum.Enum`.
119119
return Shape._cast_plain_enum(cls)
120120

121-
def __call__(cls, value):
121+
def __call__(cls, value, *args, **kwargs):
122122
# :class:`py_enum.Enum` uses ``__call__()`` for type casting: ``E(x)`` returns
123123
# the enumeration member whose value equals ``x``. In this case, ``x`` must be a concrete
124124
# value.
@@ -130,7 +130,7 @@ def __call__(cls, value):
130130
# comparisons with enum members of the wrong type.
131131
if isinstance(value, Value):
132132
return value
133-
return super().__call__(value)
133+
return super().__call__(value, *args, **kwargs)
134134

135135
def const(cls, init):
136136
# Same considerations apply as above.

tests/test_lib_enum.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,6 @@ class EnumA(Enum):
116116
r"shape used in bit vector context; define the enumeration by inheriting from "
117117
r"the class in amaranth\.lib\.enum and specifying the 'shape=' keyword argument$"):
118118
Cat(EnumA.A)
119+
120+
def test_functional(self):
121+
Enum("FOO", ["BAR", "BAZ"])

0 commit comments

Comments
 (0)