From 80f38711ecb29e7da60379199f87a0c0fa277e1e Mon Sep 17 00:00:00 2001 From: Marcus Mews Date: Fri, 20 Feb 2026 16:52:31 +0000 Subject: [PATCH] PY-87831 incorrect (invariant) variance on subtype (cherry picked from commit c0254d65914f2e6fab1b69eecc6fc4e4837b6ce7) IJ-MR-192664 GitOrigin-RevId: b8d3a12e6774ccff04d368d30a0a49572e303e1e --- .../python/psi/types/PyInferredVarianceJudgment.kt | 1 + .../jetbrains/python/PyInferredVarianceJudgmentTest.kt | 10 ++++++++++ 2 files changed, 11 insertions(+) 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, """