We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
__match_args__
runtime_checkable
Since __match_args__ is not mentioned in _SPECIAL_NAMES right now these two examples have different results:
_SPECIAL_NAMES
@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?
isinstance
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.
A
__slots__
__weakref__
__annotations__
Do others agree? CC @AlexWaygood for @runtime_checkable protocols
@runtime_checkable
I will send a PR with my proposed solution and tests :)
__instancecheck__
The text was updated successfully, but these errors were encountered:
pythongh-110682: Ignore __match_args__ from __intancecheck__ in p…
__intancecheck__
8602553
…rotocols
Related #110686
Sorry, something went wrong.
I agree that __match_args__ ought to be disregarded by isinstance() in this case.
isinstance()
gh-110682: Ignore __match_args__ from __instancecheck__ in protoc…
5257ade
…ols (#110683) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sounds like the consensus is that this was really a "missing feature" rather than a bug, so we won't be backporting this
sobolevn
No branches or pull requests
Bug report
Since
__match_args__
is not mentioned in_SPECIAL_NAMES
right 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
A
does 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_checkable
protocolsI will send a PR with my proposed solution and tests :)
Linked PRs
__match_args__
from__instancecheck__
in protocols #110683The text was updated successfully, but these errors were encountered: