plum
plum copied to clipboard
make @parametric work with classes with arbitrary metaclasses
I am experimenting with https://github.com/cgarciae/treeo and plum, and found out that since both inject meta classes they don't work together.
This PR makes plum work with classes which already have a meta class by injecting CovariantMeta
as a superclass of the existing meta class, and by redefining __call__
(essentially the constructor) to infer the parameters before calling into the existing class.
I'm surprised this was so easy to implement!
Coverage remained the same at 100.0% when pulling a0df7ac5a61443dbcfb1438b4fa2d129e0f86b10 on PhilipVinc:pv/parametricmeta into b521badf3447d61fc06ddb1956ac9e658639e9ce on wesselb:master.
Thank you, @PhilipVinc!! This really is excellent—a strict improvement. Merging this now and releasing a new version. :)
Actually, you've still marked this as a draft. The PR looks complete to me. Are you happy to have this merged?
Yeah, I think I wanted to add a test to check for what the fix issue in __init_subclass__
commit fixed.
I found out about it in a very exotic case that arises when you combine @parametric
with classes that auto-register themselves with jax, but it's a real issue of plum,.
I'll add a test soon