Repository: beartype/plum

Issue:
`parametric` conflicts with certain usages of customized `__init_subclass__`
Hi!

I'm using JAX, and also using `plum` -- in my library, I've define a mixin class called `Pytree` which automatically implements the Pytree interface for classes which mix it in.

It's quite simple:

```python
class Pytree:
    def __init_subclass__(cls, **kwargs):
        jtu.register_pytree_node(
            cls,
            cls.flatten,
            cls.unflatten,
        )

```

If I wish to use this mixin, and `parametric` -- I'm in for problems, I get duplicate registration:

```
ERROR ... ValueError: Duplicate custom PyTreeDef type registration for <class...>
```

I'm not exactly sure why this occurs, but I'm hoping to find a fix -- because I'd like to use parametric classes to guide some of the dispatch in my library functions.

Discussion:

Patch:
diff --git a/plum/parametric.py b/plum/parametric.py
index ec69cf3..12aafa3 100644
--- a/plum/parametric.py
+++ b/plum/parametric.py
@@ -240,7 +240,7 @@ def parametric(original_class=None):
                 return original_class.__new__(cls)
 
             cls.__new__ = class_new
-        original_class.__init_subclass__(**kw_args)
+        super(original_class, cls).__init_subclass__(**kw_args)
 
     # Create parametric class.
     parametric_class = meta(


Test patch:
diff --git a/tests/test_parametric.py b/tests/test_parametric.py
index d9fa79c..00bbcfa 100644
--- a/tests/test_parametric.py
+++ b/tests/test_parametric.py
@@ -507,3 +507,25 @@ def test_val():
         Val[1].__init__(MockVal())
 
     assert repr(Val[1]()) == "plum.parametric.Val[1]()"
+
+
+def test_init_subclass_correct_args():
+    # See issue https://github.com/beartype/plum/issues/105
+
+    from plum import parametric
+
+    register = set()
+
+    class Pytree:
+        def __init_subclass__(cls, **kwargs):
+            if cls in register:
+                raise ValueError("duplicate")
+            else:
+                register.add(cls)
+
+    @parametric
+    class Wrapper(Pytree):
+        pass
+
+    Wrapper[int]
+    assert Wrapper[int] in register