We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
__instancecheck__
This code does not work:
from classes import typeclass class Meta(type): def __instancecheck__(self, other) -> bool: return other == 1 class Some(object, metaclass=Meta): ... @typeclass def some(instance) -> bool: ... @some.instance(Some) def _some_some(instance: Some) -> bool: return True print(some(1)) # NotImplementedError: Missing matched typeclass instance for type: int
But, it should! For example, phantom-types use this method: https://github.com/antonagestam/phantom-types/blob/main/phantom/base.py#L28-L43
phantom-types
If we want to support them - we would need this feature.
I suggest that we need to add types with __instancecheck__ defined to both ._instances and ._protocols. This way both of these cases would work:
._instances
._protocols
print(some(Some())) print(some(1))
This code does not work:
But, it should! For example,
phantom-typesuse this method: https://github.com/antonagestam/phantom-types/blob/main/phantom/base.py#L28-L43If we want to support them - we would need this feature.
Solution
I suggest that we need to add types with
__instancecheck__defined to both._instancesand._protocols.This way both of these cases would work: