Open
Description
Currently mypy accepts this unsafe code:
from typing import Generic, TypeVar, List
T = TypeVar('T')
class B(Generic[T]):
x: List[T] = []
class C1(B[int]):
pass
class C2(B[str]):
pass
C1().x.append(42)
C2().x.append('Hm...')
A potential solution would be to disallow all default values for generic attributes except None
. This is however a low priority, since it is a false negative, and a rare corner case.