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
ValueCastable and ShapeCastable should override __instancecheck__ #753
Comments
This requires defining a metaclass for ShapeCastable and ValueCastable, which can potentially have unexpected consequences. Needs investigating. |
On reflection, this may not be such a good idea for two reasons:
So maybe we should document that the only way to test if an object is shape-castable is through |
Looking deeper into it, import abc
class ValueCastable(metaclass=abc.ABCMeta):
@classmethod
def __subclasshook__(cls, other):
if other in (int,):
return True
return NotImplemented
print(issubclass(int, ValueCastable)) # => True
print(isinstance(1, ValueCastable)) # => True This handles objection (1); it is clearly fine to use the Python mechanism for defining protocols. Objection (2a) can be handled by saying that the only thing Objection (2b) is handled by only returning So I think we actually should do this change. |
We've discussed this issue on the 2023-05-15 weekly meeting. The disposition was to merge the PR implementing the proposed changes. |
RFC 35 will resolve this issue. |
Resolved by #983. |
Right now,
isinstance(unsigned(1), ShapeCastable)
orisinstance(Cat(), ValueCastable)
orisinstance(1, ValueCastable)
are all false, which is wrong.The text was updated successfully, but these errors were encountered: