Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

__match_args__ +runtime_checkable protocol #110682

Closed
Assignees
sobolevn
Labels
@sobolevn

Description

@sobolevn

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?

  1. 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.

  1. 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

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp