Cannot infer generic parameter types within match
statements
#18432
Labels
bug
mypy got something wrong
match
statements
#18432
Bug Report
Related to #13612.
#13618 fixed the error reported in #13612, so mypy correctly infers the type of the unpacked value.
However, mypy does not correctly infer the type parameter of the class containing the generic attribute within the scope of the
match
statement, despite correct inference outside the statement.To Reproduce
Extending the reprex from #13612:
Expected Behavior
Within the
match
statement,A(x)
should be inferred to be of typeA[str]
.I have found that
pyright
, or at least thepylance
VS code extension, infers this correctly. See below:Actual Behavior
The final line does not reveal
A[str]
.Your Environment
mypy.ini
(and other config files): noneMotivation
This becomes relevant when trying to match on a union of generic types, as it creates an
unreachable
error.e.g.
The text was updated successfully, but these errors were encountered: