Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Since__match_args__ is not mentioned in_SPECIAL_NAMES right now these two examples have different results:
@runtime_checkableclassP(Protocol):x:inty:intclassA:def__init__(self,x:int,y:int):self.x=xself.y=yassertisinstance(A(1,2),P)isTrue
And:
@runtime_checkableclassP(Protocol):__match_args__= ('x','y')x:inty:intclassA:def__init__(self,x:int,y:int):self.x=xself.y=yassertisinstance(A(1,2),P)isFalse
Why I think that__match_args__ is a special attribute and should not be checked inisinstance?
- It might be useed for protocol itself in patma (new issue is on its way about it):
matchA(1,2):caseP(x,y):print(x,y)
But, this does not work right now ifA 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 :)