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 :)
Linked PRs
Bug report
Since
__match_args__is not mentioned in_SPECIAL_NAMESright now these two examples have different results:And:
Why I think that
__match_args__is a special attribute and should not be checked inisinstance?But, this does not work right now if
Adoes not have__match_args__. Which is not really required for this case.__slots__and__weakref__and__annotations__are ignored alreadyDo others agree?
CC @AlexWaygood for
@runtime_checkableprotocolsI will send a PR with my proposed solution and tests :)
Linked PRs
__match_args__from__instancecheck__in protocols #110683