Cannot deduce type of generic attributes within match statements #13612
Labels
bug
mypy got something wrong
topic-match-statement
Python 3.10's match statement
topic-type-narrowing
Conditional type narrowing / binder
Bug Report
It seems like
mypy
is having trouble deducing the type of generic attributes inmatch
statements. If__match_args__
contains a generic attribute, this attribute becomesAny
aftercase
matching.To Reproduce
Run
mypy
on the code belowExpected Behavior
The total output should be:
Actual Behavior
the last line doesn't reveal
builtins.str
Your Environment
master
branch)mypy.ini
(and other config files): noneWhat I've found so far
If we declare
A
as a minimal dataclass the attribute is correctly inferred!If the
case
explicitly matches on the attribute name, it also correctly infers the type:Issue
mypy
unable to narrow type of tuple elements incase
clause in pattern matching #12364 may be relatedPEP626 mentions generics are special, but the examples don't appear relevant to this case.
The text was updated successfully, but these errors were encountered: