From 95224d313299d499311e2be95f047b857041ba79 Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Sat, 16 May 2026 11:27:30 +0200 Subject: [PATCH 1/2] added variance inference test with method scoped type variable and bound self type --- .../results/mypy/generics_variance_inference.toml | 5 ++++- .../pycroscope/generics_variance_inference.toml | 1 + .../results/pyrefly/generics_variance_inference.toml | 1 + .../results/pyright/generics_variance_inference.toml | 4 ++++ conformance/results/results.html | 4 ++-- .../results/ty/generics_variance_inference.toml | 5 ++++- .../results/zuban/generics_variance_inference.toml | 6 +++++- conformance/tests/generics_variance_inference.py | 11 +++++++++++ 8 files changed, 32 insertions(+), 5 deletions(-) diff --git a/conformance/results/mypy/generics_variance_inference.toml b/conformance/results/mypy/generics_variance_inference.toml index b1158c7e9..a4e0636e7 100644 --- a/conformance/results/mypy/generics_variance_inference.toml +++ b/conformance/results/mypy/generics_variance_inference.toml @@ -23,7 +23,10 @@ generics_variance_inference.py:169: error: Incompatible types in assignment (exp generics_variance_inference.py:170: error: Incompatible types in assignment (expression has type "ShouldBeInvariant6[int]", variable has type "ShouldBeInvariant6[float]") [assignment] generics_variance_inference.py:181: error: Incompatible types in assignment (expression has type "ShouldBeCovariant6[float]", variable has type "ShouldBeCovariant6[int]") [assignment] generics_variance_inference.py:194: error: Incompatible types in assignment (expression has type "ShouldBeContravariant2[int]", variable has type "ShouldBeContravariant2[float]") [assignment] +generics_variance_inference.py:204: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[int]", variable has type "ShouldBeCovariant7[object]") [assignment] +generics_variance_inference.py:205: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[object]", variable has type "ShouldBeCovariant7[int]") [assignment] """ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 204: Unexpected errors ['generics_variance_inference.py:204: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[int]", variable has type "ShouldBeCovariant7[object]") [assignment]'] """ diff --git a/conformance/results/pycroscope/generics_variance_inference.toml b/conformance/results/pycroscope/generics_variance_inference.toml index 56b1fa57b..e968d354f 100644 --- a/conformance/results/pycroscope/generics_variance_inference.toml +++ b/conformance/results/pycroscope/generics_variance_inference.toml @@ -25,4 +25,5 @@ output = """ ./generics_variance_inference.py:170:0: Incompatible assignment: expected generics_variance_inference.ShouldBeInvariant6[float | int], got generics_variance_inference.ShouldBeInvariant6[int] [incompatible_assignment] ./generics_variance_inference.py:181:0: Incompatible assignment: expected generics_variance_inference.ShouldBeCovariant6[int], got generics_variance_inference.ShouldBeCovariant6[float | int] [incompatible_assignment] ./generics_variance_inference.py:194:0: Incompatible assignment: expected generics_variance_inference.ShouldBeContravariant2[float | int], got generics_variance_inference.ShouldBeContravariant2[int] [incompatible_assignment] +./generics_variance_inference.py:205:0: Incompatible assignment: expected generics_variance_inference.ShouldBeCovariant7[int], got generics_variance_inference.ShouldBeCovariant7[object] [incompatible_assignment] """ diff --git a/conformance/results/pyrefly/generics_variance_inference.toml b/conformance/results/pyrefly/generics_variance_inference.toml index 8035068c3..612ceca73 100644 --- a/conformance/results/pyrefly/generics_variance_inference.toml +++ b/conformance/results/pyrefly/generics_variance_inference.toml @@ -26,4 +26,5 @@ ERROR generics_variance_inference.py:169:31-58: `ShouldBeInvariant6[float]` is n ERROR generics_variance_inference.py:170:33-58: `ShouldBeInvariant6[int]` is not assignable to `ShouldBeInvariant6[float]` [bad-assignment] ERROR generics_variance_inference.py:181:31-58: `ShouldBeCovariant6[float]` is not assignable to `ShouldBeCovariant6[int]` [bad-assignment] ERROR generics_variance_inference.py:194:37-66: `ShouldBeContravariant2[int]` is not assignable to `ShouldBeContravariant2[float]` [bad-assignment] +ERROR generics_variance_inference.py:205:31-59: `ShouldBeCovariant7[object]` is not assignable to `ShouldBeCovariant7[int]` [bad-assignment] """ diff --git a/conformance/results/pyright/generics_variance_inference.toml b/conformance/results/pyright/generics_variance_inference.toml index 9a378ad6f..1bbd86ed4 100644 --- a/conformance/results/pyright/generics_variance_inference.toml +++ b/conformance/results/pyright/generics_variance_inference.toml @@ -79,6 +79,10 @@ generics_variance_inference.py:194:37 - error: Type "ShouldBeContravariant2[int]   "ShouldBeContravariant2[int]" is not assignable to "ShouldBeContravariant2[float]"     Type parameter "T@ShouldBeContravariant2" is contravariant, but "int" is not a supertype of "float"       "float" is not assignable to "int" (reportAssignmentType) +generics_variance_inference.py:205:31 - error: Type "ShouldBeCovariant7[object]" is not assignable to declared type "ShouldBeCovariant7[int]" +  "ShouldBeCovariant7[object]" is not assignable to "ShouldBeCovariant7[int]" +    Type parameter "T@ShouldBeCovariant7" is covariant, but "object" is not a subtype of "int" +      "object" is not assignable to "int" (reportAssignmentType) """ conformance_automated = "Pass" errors_diff = """ diff --git a/conformance/results/results.html b/conformance/results/results.html index 7543ecaeb..1b92fd8a8 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -520,10 +520,10 @@

Python Type System Conformance Test Results

     generics_variance_inference Pass Pass +Unknown Pass Pass -Pass -Pass +Unknown Type qualifiers diff --git a/conformance/results/ty/generics_variance_inference.toml b/conformance/results/ty/generics_variance_inference.toml index 1c637eecf..3479ef2d2 100644 --- a/conformance/results/ty/generics_variance_inference.toml +++ b/conformance/results/ty/generics_variance_inference.toml @@ -1,5 +1,6 @@ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 204: Unexpected errors ['generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]`'] """ output = """ generics_variance_inference.py:24:33: error[invalid-assignment] Object of type `ClassA[int | float, int, int]` is not assignable to `ClassA[int, int, int]` @@ -25,4 +26,6 @@ generics_variance_inference.py:169:31: error[invalid-assignment] Object of type generics_variance_inference.py:170:33: error[invalid-assignment] Object of type `ShouldBeInvariant6[int]` is not assignable to `ShouldBeInvariant6[int | float]` generics_variance_inference.py:181:31: error[invalid-assignment] Object of type `ShouldBeCovariant6[int | float]` is not assignable to `ShouldBeCovariant6[int]` generics_variance_inference.py:194:37: error[invalid-assignment] Object of type `ShouldBeContravariant2[int]` is not assignable to `ShouldBeContravariant2[int | float]` +generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]` +generics_variance_inference.py:205:31: error[invalid-assignment] Object of type `ShouldBeCovariant7[object]` is not assignable to `ShouldBeCovariant7[int]` """ diff --git a/conformance/results/zuban/generics_variance_inference.toml b/conformance/results/zuban/generics_variance_inference.toml index 722cb1739..33987312c 100644 --- a/conformance/results/zuban/generics_variance_inference.toml +++ b/conformance/results/zuban/generics_variance_inference.toml @@ -1,5 +1,6 @@ -conformance_automated = "Pass" +conformance_automated = "Fail" errors_diff = """ +Line 200: Unexpected errors ['generics_variance_inference.py:200: error: Name "S" is not defined [name-defined]', 'generics_variance_inference.py:200: error: Name "S" is not defined [name-defined]'] """ output = """ generics_variance_inference.py:24: error: Incompatible types in assignment (expression has type "ClassA[float, int, int]", variable has type "ClassA[int, int, int]") [assignment] @@ -25,4 +26,7 @@ generics_variance_inference.py:169: error: Incompatible types in assignment (exp generics_variance_inference.py:170: error: Incompatible types in assignment (expression has type "ShouldBeInvariant6[int]", variable has type "ShouldBeInvariant6[float]") [assignment] generics_variance_inference.py:181: error: Incompatible types in assignment (expression has type "ShouldBeCovariant6[float]", variable has type "ShouldBeCovariant6[int]") [assignment] generics_variance_inference.py:194: error: Incompatible types in assignment (expression has type "ShouldBeContravariant2[int]", variable has type "ShouldBeContravariant2[float]") [assignment] +generics_variance_inference.py:200: error: Name "S" is not defined [name-defined] +generics_variance_inference.py:200: error: Name "S" is not defined [name-defined] +generics_variance_inference.py:205: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[object]", variable has type "ShouldBeCovariant7[int]") [assignment] """ diff --git a/conformance/tests/generics_variance_inference.py b/conformance/tests/generics_variance_inference.py index 0a1cd41cd..a1fde4da7 100644 --- a/conformance/tests/generics_variance_inference.py +++ b/conformance/tests/generics_variance_inference.py @@ -192,3 +192,14 @@ class ShouldBeContravariant2[T](Parent_Contravariant[T]): c1: ShouldBeContravariant2[int] = ShouldBeContravariant2[float]() # OK c2: ShouldBeContravariant2[float] = ShouldBeContravariant2[int]() # E + +class ShouldBeCovariant7[T]: + def get(self) -> T: + raise NotImplementedError + + def add[S](self: "ShouldBeCovariant7[S]", other: list[S]) -> "ShouldBeCovariant7[S]": + raise NotImplementedError + + +d1: ShouldBeCovariant7[object] = ShouldBeCovariant7[int]() # OK +d2: ShouldBeCovariant7[int] = ShouldBeCovariant7[object]() # E From 6d2e26652415c1fd2b6db496b7b1cbcd96ae7d8b Mon Sep 17 00:00:00 2001 From: Randolf Scholz Date: Mon, 25 May 2026 10:30:57 +0200 Subject: [PATCH 2/2] updated conformance results for ty --- conformance/results/results.html | 2 +- conformance/results/ty/generics_variance_inference.toml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/conformance/results/results.html b/conformance/results/results.html index 47dcfa786..efed999b2 100644 --- a/conformance/results/results.html +++ b/conformance/results/results.html @@ -523,7 +523,7 @@

Python Type System Conformance Test Results

Unknown Pass Pass -Unknown +Pass Type qualifiers diff --git a/conformance/results/ty/generics_variance_inference.toml b/conformance/results/ty/generics_variance_inference.toml index 3479ef2d2..110ceaa3a 100644 --- a/conformance/results/ty/generics_variance_inference.toml +++ b/conformance/results/ty/generics_variance_inference.toml @@ -1,6 +1,5 @@ -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 204: Unexpected errors ['generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]`'] """ output = """ generics_variance_inference.py:24:33: error[invalid-assignment] Object of type `ClassA[int | float, int, int]` is not assignable to `ClassA[int, int, int]` @@ -26,6 +25,5 @@ generics_variance_inference.py:169:31: error[invalid-assignment] Object of type generics_variance_inference.py:170:33: error[invalid-assignment] Object of type `ShouldBeInvariant6[int]` is not assignable to `ShouldBeInvariant6[int | float]` generics_variance_inference.py:181:31: error[invalid-assignment] Object of type `ShouldBeCovariant6[int | float]` is not assignable to `ShouldBeCovariant6[int]` generics_variance_inference.py:194:37: error[invalid-assignment] Object of type `ShouldBeContravariant2[int]` is not assignable to `ShouldBeContravariant2[int | float]` -generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]` generics_variance_inference.py:205:31: error[invalid-assignment] Object of type `ShouldBeCovariant7[object]` is not assignable to `ShouldBeCovariant7[int]` """