Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
Open
Description
Bug Report
When type checking the binding parameters of a match case expression, the binding completely fails if the class has a generic superclass and the match is located in a generic function, though the binding succeeds if the enclosing function is not generic.
To Reproduce
fromtypingimportAnyclassMyBase[T]:passclassMyData(MyBase[int]):__match_args__= ("a","b")def__init__(self,a:str,b:bool)->None:self.a=aself.b=bdefhandle_mydata_ok(val:MyBase[Any])->None:matchval:caseMyData(_a,_b):passdefhandle_mydata_not_ok[T](val:MyBase[T])->None:matchval:caseMyData(_a,_b):pass
https://mypy-play.net/?mypy=latest&python=3.12&gist=d8b1f6586d82fab7ead1a3d76a9962cf
Expected Behavior
mypy should report no type errors for bothhandle_mydata_ok
andhandle_mydata_not_ok
Actual Behavior
main.py:20: error: Class "__main__.MyData" has no attribute "a" [misc]main.py:20: error: Class "__main__.MyData" has no attribute "b" [misc]Found 2 errors in 1 file (checked 1 source file)
Your Environment
Check the mypy-play link for the reproduction.
- Mypy version used: 1.16.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: 3.12