Back to Intellij Community

PyVarianceInspection

python/python-psi-impl/resources/inspectionDescriptions/PyVarianceInspection.html

2025.3-rc-2319 B
Original Source

Reports incorrect use of Python type variables due to variance issues.

Incompatible variance

from typing import TypeVar, Generic
T = TypeVar("T", covariant=True)
class C(Generic[T]):
    def method(self, t: T): # at 'T': A covariant type variable cannot be used in this contravariant position
        pass