Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Closed
Description
Bug Report
When checking a function with argument oftype[SomeTypeVar], class attributes are considered missing.
To Reproduce
fromtypingimportClassVar,Type,TypeVar,castclassOne:PATTERN:ClassVar[str]=r"^([a-z]{3})$"classTwo:PATTERN:ClassVar[str]=r"^([0-9]{3})$"_T=TypeVar("_T",bound=One|Two)deffoo(result_type:Type[_T])->_T:result_type.PATTERN# E: "Type[_T]" has no attribute "PATTERN" [attr-defined]returncast(_T,result_type())foo(One)foo(Two)
This doesn't depend onClassVar and works withFinal or plainstr as well.
Gist:https://mypy-play.net/?mypy=master&python=3.10&gist=2d769a9767898e71431e59df1c2f8488
Expected Behavior
No errors (let's ignorecast for now, it's another unrelated issue).
Actual Behavior
main.py:12: error: "Type[_T]" has no attribute "PATTERN" [attr-defined]Found 1 error in 1 file (checked 1 source file)Your Environment
- Mypy version used: 1.0.0 and master
- Mypy command-line flags: not related
- Mypy configuration options from
mypy.ini(and other config files): not related - Python version used: 3.9-3.11, not related
Discovered inthis SO question