-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #105 #106
Fix #105 #106
Conversation
@femtomc CI is broken by the latest release of bear type, but this should work. Can you test it on your code and let me know if it solves it even in the more realistic/complex scenario? |
Will do, one moment. |
@PhilipVinc That fix works to get past the first error! -- but I'm actually finding now that some of my methods (defined via E.g. in a base class (call it
Now, in a subclass which mixes in However, this fails on the resolver:
I can pull this into a separate issue. Edit: just to be clear, it also fails on the dispatch definition with this signature: @dispatch
def update(
self,
key: Any,
prev: Any,
new_constraints: Mask[ChoiceMap],
argdiffs: Any,
) -> Any: e.g. totally permissive except for my parametric class |
If you can provide a MWE that does not work I can give a look. |
There is one failing test, but that failure seems unrelated to this, so I'm happy to merge this if you are too. :) @PhilipVinc and @femtomc, I believe this might be the MWE that you are looking for: from numbers import Number
from plum import parametric
@parametric
class A:
def __init__(self, x):
self.x = x Then >>> issubclass(A[int], A[int]) # Just a check
True
>>> issubclass(A[int], A[Number]) # Covariance!
True
>>> isinstance(A[int](None), A[Number]) # Here is where it goes wrong :((( This breaks dispatch.
False I've been vaguely aware of this for a while, but never really took the time to dig into it. The problem is that we have not implemented Here's how that would work in the above example: from numbers import Number
from plum import parametric
class AMeta(type):
def __instancecheck__(self, x):
return issubclass(type(x), self)
@parametric
class A(metaclass=AMeta):
def __init__(self, x):
self.x = x Then >>> issubclass(A[int], A[int])
True
>>> issubclass(A[int], A[Number])
True
>>> isinstance(A[int](None), A[Number])
True so we're all good. I have two concerns about this:
|
yes the failure is unrelated and due to the resolve pep bug in beartype. I'll merge this fix and we can experiment with fixing the other issue raised in a separate PR. |
We were providing the wrong class to the
__init_subclass__
called in our initialisation of parametric subclasses. This fixes it and adds a test.