Bug Report
mypy has trouble inferring the type of generic attributes in match statements when inheritance is involved.
This issue was encountered while investigating #13612
To Reproduce
fromtypingimportGeneric, TypeVarT=TypeVar("T")
classBase(Generic[T]):
...
classA(Base[T]):
x: T__match_args__= ('x', )
def__init__(self, x: T):
self.x=xa: Base[str] =A("foo")
reveal_type(a) # Base[str] (correct)matcha:
caseA(b):
reveal_type(b) # Any (incorrect! Should be builtins.str)Expected Behavior
The attribute on the last line above is revealed to be str
Actual Behavior
It is revealed to be Any
Your Environment
- Mypy version used:
mypy-0.980+dev.b031f1c04e1ee4331e4d6957c7a9b727293328a9 - Mypy command-line flags: none
- Mypy configuration options from
mypy.ini (and other config files): none - Python version used: 3.10.5
- Operating system and version: n/a
Bug Report
mypyhas trouble inferring the type of generic attributes inmatchstatements when inheritance is involved.This issue was encountered while investigating #13612
To Reproduce
Expected Behavior
The attribute on the last line above is revealed to be
strActual Behavior
It is revealed to be
AnyYour Environment
mypy-0.980+dev.b031f1c04e1ee4331e4d6957c7a9b727293328a9mypy.ini(and other config files): none