Closed
Description
Bug Report
Mypy reports an issue with subclassing generic class using ParamSpec
, but only when the base class is referenced via module attribute access.
To Reproduce
File test1.py
from typing import Generic, ParamSpec
P = ParamSpec("P")
class Base(Generic[P]):
def test(self, *args: P.args, **kwargs: P.kwargs):
raise NotImplementedError
File test2_good.py
from test1 import Base
class Derived(Base[[int]]):
def test(self, x: int):
print(x)
File test2_bad.py
import test1
class Derived(test1.Base[[int]]):
def test(self, x: int):
print(x)
Expected Behavior
When running Mypy against the test2_good.py
file, no issues are reported. This is what I expect.
(venv) debian@25081d5e7e53:/workspace$ mypy test2_good.py
Success: no issues found in 1 source file
Actual Behavior
When running Mypy against the test2_bad.py
file, an issue is reported. The only difference is how the base class is specified.
(venv) debian@25081d5e7e53:/workspace$ mypy test2_bad.py
test2_bad.py:4: error: Bracketed expression "[...]" is not valid as a type [valid-type]
test2_bad.py:4: note: Did you mean "List[...]"?
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.0.1 (compiled: yes)
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.10.8 from the official Docker image