diff --git a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyInferredVarianceJudgment.kt b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyInferredVarianceJudgment.kt index 62a0677e1f92..35fe8634c93e 100644 --- a/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyInferredVarianceJudgment.kt +++ b/python/python-psi-impl/src/com/jetbrains/python/psi/types/PyInferredVarianceJudgment.kt @@ -107,6 +107,7 @@ object PyInferredVarianceJudgment { collector.usages.contains(COVARIANT) && collector.usages.contains(CONTRAVARIANT) -> INVARIANT collector.usages.contains(COVARIANT) -> COVARIANT collector.usages.contains(CONTRAVARIANT) -> CONTRAVARIANT + collector.usages.contains(BIVARIANT) -> BIVARIANT else -> INVARIANT } } diff --git a/python/testSrc/com/jetbrains/python/PyInferredVarianceJudgmentTest.kt b/python/testSrc/com/jetbrains/python/PyInferredVarianceJudgmentTest.kt index 1b1a34d4e5ea..00a0e59edf3d 100644 --- a/python/testSrc/com/jetbrains/python/PyInferredVarianceJudgmentTest.kt +++ b/python/testSrc/com/jetbrains/python/PyInferredVarianceJudgmentTest.kt @@ -139,6 +139,16 @@ internal class PyInferredVarianceJudgmentTest : PyTestCase() { """) } + fun `test Generic sub class unused`() { + // see comment about bivariance in: PyInferredVarianceJudgment.doGetInferredVariance + doTest("T", Variance.BIVARIANT, """ + class A[S]: + ... + class B[T](A[T]): + def method(self): pass + """) + } + fun `test Generic class unused TypeVar syntax`() { // see comment about bivariance in: PyInferredVarianceJudgment.doGetInferredVariance doTest("T])", Variance.BIVARIANT, PyReferenceExpression::class.java, """