PY-87831 incorrect (invariant) variance on subtype

(cherry picked from commit c0254d65914f2e6fab1b69eecc6fc4e4837b6ce7)

IJ-MR-192664

GitOrigin-RevId: b8d3a12e6774ccff04d368d30a0a49572e303e1e
This commit is contained in:
Marcus Mews
2026-02-21 11:10:10 +00:00
committed by intellij-monorepo-bot
parent 2bf9d316a5
commit 80f38711ec
2 changed files with 11 additions and 0 deletions
@@ -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
}
}
@@ -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, """