Repository: amaranth-lang/amaranth (python)

Issue:
`amaranth.lib.enum` does not support functional syntax
Functional syntax defined [here](https://docs.python.org/3/library/enum.html):

```python
# functional syntax
Color = Enum('Color', ['RED', 'GREEN', 'BLUE'])
```

MCVE:

```python
import enum as pyenum
import amaranth.lib.enum
pyenum.Enum("FOO", ["BAR", "BAZ"])
enum.Enum("FOO", ["BAR", "BAZ"])
```

Results:

```
TypeError                                 Traceback (most recent call last)
Cell In[44], line 4
      2 import amaranth.lib.enum
      3 pyenum.Enum("FOO", ["BAR", "BAZ"])
----> 4 enum.Enum("FOO", ["BAR", "BAZ"])

TypeError: EnumMeta.__call__() takes 2 positional arguments but 3 were given
```

Pull request description:
lib.enum: allow using functional syntax for enum creation.
Fixes #910.

Patch:
diff --git a/amaranth/lib/enum.py b/amaranth/lib/enum.py
index 10c3666..6dc70e7 100644
--- a/amaranth/lib/enum.py
+++ b/amaranth/lib/enum.py
@@ -118,7 +118,7 @@ class EnumMeta(ShapeCastable, py_enum.EnumMeta):
             # replacement for `enum.Enum`.
             return Shape._cast_plain_enum(cls)
 
-    def __call__(cls, value):
+    def __call__(cls, value, *args, **kwargs):
         # :class:`py_enum.Enum` uses ``__call__()`` for type casting: ``E(x)`` returns
         # the enumeration member whose value equals ``x``. In this case, ``x`` must be a concrete
         # value.
@@ -130,7 +130,7 @@ class EnumMeta(ShapeCastable, py_enum.EnumMeta):
         # comparisons with enum members of the wrong type.
         if isinstance(value, Value):
             return value
-        return super().__call__(value)
+        return super().__call__(value, *args, **kwargs)
 
     def const(cls, init):
         # Same considerations apply as above.


Test patch:
diff --git a/tests/test_lib_enum.py b/tests/test_lib_enum.py
index 9d5a27e..5c86d60 100644
--- a/tests/test_lib_enum.py
+++ b/tests/test_lib_enum.py
@@ -116,3 +116,6 @@ class EnumTestCase(FHDLTestCase):
                 r"shape used in bit vector context; define the enumeration by inheriting from "
                 r"the class in amaranth\.lib\.enum and specifying the 'shape=' keyword argument$"):
             Cat(EnumA.A)
+
+    def test_functional(self):
+        Enum("FOO", ["BAR", "BAZ"])