Closed
Description
Bug report
There are different simple and corner cases that we need to tests.
Why is that important? Because runtime_checkable
Protocol
has its own __instancecheck__
magic that must work correctly with match
machinery.
>>> import typing, dataclasses
>>> @typing.runtime_checkable
... class P(typing.Protocol):
... a: int
...
>>> @dataclasses.dataclass
... class D:
... a: int
...
>>> match D(1):
... case P() as p:
... print(p)
...
D(a=1)
>>> @typing.runtime_checkable
... class P(typing.Protocol):
... a: int
... b: int
...
>>> @dataclasses.dataclass
... class D:
... a: int
... b: int
...
>>> match D(1, 2):
... case P(b=b1):
... print(b1)
...
2
I have a PR ready.
CC @AlexWaygood for runtime_checkable
and @brandtbucher for match
Requires #110682 to test multiple cases with Protocol
and __match_args__
.