Mypy does not detect the case where a covariant or contravariant class (i.e. a class that is parameterized by a class-scoped covariant or contravariant TypeVar) derives from an invariant class. This creates a type correctness hole as shown in the following code sample.
fromtypingimportTypeVarT=TypeVar("T", covariant=True)
classMyList(list[T]): passdefappend_float(y: MyList[float]):
y.append(1.0)
x: MyList[int] =MyList([1, 2, 3])
append_float(x)Pyright likewise did not previously catch this case. I just added the check here.
Mypy does not detect the case where a covariant or contravariant class (i.e. a class that is parameterized by a class-scoped covariant or contravariant TypeVar) derives from an invariant class. This creates a type correctness hole as shown in the following code sample.
Pyright likewise did not previously catch this case. I just added the check here.