Bug Report
mypy shows a syntax error ("Type parameter lists are only supported in Python 3.12 and greater") meeting type parameters in stub files.
To Reproduce
test.pyi
class A[T]:
def __init__(self, a: T):
self.a = a
def test(a: A[int]):
a.a
And run 3 following commands:
py -3.11 -m mypy test.pyi
py -3.12 -m mypy test.pyi
py -3.12 -m mypy test.pyi --python-version 3.9
Expected Behavior
For mypy finish without errors in all cases since docs state that stub files support all latest typing features except type keyword.
https://typing.readthedocs.io/en/latest/guides/writing_stubs.html?utm_source=chatgpt.com#language-features
Actual Behavior
Success only for Python 3.12+ with python-version 3.12+.
> py -3.11 -m mypy test.pyi
test.pyi:2: error: invalid syntax [syntax]
Found 1 error in 1 file (errors prevented further checking)
> py -3.12 -m mypy test.pyi
Success: no issues found in 1 source file
> py -3.12 -m mypy test.pyi --python-version 3.9
test.pyi:2: error: Type parameter lists are only supported in Python 3.12 and greater [syntax]
Found 1 error in 1 file (errors prevented further checking)
Your Environment
- Mypy version used: 1.15
- Python version used: 3.11 / 3.12
Bug Report
mypy shows a syntax error ("Type parameter lists are only supported in Python 3.12 and greater") meeting type parameters in stub files.
To Reproduce
test.pyi
And run 3 following commands:
Expected Behavior
For mypy finish without errors in all cases since docs state that stub files support all latest typing features except
typekeyword.https://typing.readthedocs.io/en/latest/guides/writing_stubs.html?utm_source=chatgpt.com#language-features
Actual Behavior
Success only for Python 3.12+ with python-version 3.12+.
Your Environment