Closed
Description
Bug report
Since __match_args__
is not mentioned in _SPECIAL_NAMES
right now these two examples have different results:
@runtime_checkable
class P(Protocol):
x: int
y: int
class A:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
assert isinstance(A(1, 2), P) is True
And:
@runtime_checkable
class P(Protocol):
__match_args__ = ('x', 'y')
x: int
y: int
class A:
def __init__(self, x: int, y: int):
self.x = x
self.y = y
assert isinstance(A(1, 2), P) is False
Why I think that __match_args__
is a special attribute and should not be checked in isinstance
?
- It might be useed for protocol itself in patma (new issue is on its way about it):
match A(1, 2):
case P(x, y):
print(x, y)
But, this does not work right now if A
does not have __match_args__
. Which is not really required for this case.
- Several similar attributes like
__slots__
and__weakref__
and__annotations__
are ignored already
Do others agree?
CC @AlexWaygood for @runtime_checkable
protocols
I will send a PR with my proposed solution and tests :)