Closed as not planned
Description
Bug Report
Mypy complains that "Access to generic class variables is ambiguous" when using the CRTP technique, even though the type of the class variable in question is actually known.
To Reproduce
Save the following Python program:
from typing import TypeVar, Type, Generic, ClassVar, Any
T = TypeVar("T", bound="Base[Any]")
class Base(Generic[T]):
instance_list: ClassVar[list[T]]
@classmethod
def init(cls: Type[T]) -> None:
cls.instance_list = []
class Derived(Base["Derived"]):
pass
Derived.init()
print(Derived.instance_list)
Actual Behavior
Executing mypy test.py
outputs:
test.py:15: error: Access to generic class variables is ambiguous
Found 1 error in 1 file (checked 1 source file)
Expected Behavior
Mypy should not output errors, because Derived
inherits the class Base[Derived]
and therefore Derived
has the member variable instance_list: ClassVar[list[Derived]]
. Clearly the type is not generic or ambiguous at this point.
Your Environment
- Mypy version used: mypy 0.910
- Mypy command-line flags: none, see above
- Mypy configuration options from
mypy.ini
(and other config files): none - Python version used: Python 3.9.6
- Operating system and version: Windows 10.0.19042