Skip to content

Commit 95224d3

Browse files
added variance inference test with method scoped type variable and bound self type
1 parent 3cdfa08 commit 95224d3

8 files changed

Lines changed: 32 additions & 5 deletions

‎conformance/results/mypy/generics_variance_inference.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ generics_variance_inference.py:169: error: Incompatible types in assignment (exp
2323
generics_variance_inference.py:170: error: Incompatible types in assignment (expression has type "ShouldBeInvariant6[int]", variable has type "ShouldBeInvariant6[float]") [assignment]
2424
generics_variance_inference.py:181: error: Incompatible types in assignment (expression has type "ShouldBeCovariant6[float]", variable has type "ShouldBeCovariant6[int]") [assignment]
2525
generics_variance_inference.py:194: error: Incompatible types in assignment (expression has type "ShouldBeContravariant2[int]", variable has type "ShouldBeContravariant2[float]") [assignment]
26+
generics_variance_inference.py:204: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[int]", variable has type "ShouldBeCovariant7[object]") [assignment]
27+
generics_variance_inference.py:205: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[object]", variable has type "ShouldBeCovariant7[int]") [assignment]
2628
"""
27-
conformance_automated = "Pass"
29+
conformance_automated = "Fail"
2830
errors_diff = """
31+
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]']
2932
"""

‎conformance/results/pycroscope/generics_variance_inference.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ output = """
2525
./generics_variance_inference.py:170:0: Incompatible assignment: expected generics_variance_inference.ShouldBeInvariant6[float | int], got generics_variance_inference.ShouldBeInvariant6[int] [incompatible_assignment]
2626
./generics_variance_inference.py:181:0: Incompatible assignment: expected generics_variance_inference.ShouldBeCovariant6[int], got generics_variance_inference.ShouldBeCovariant6[float | int] [incompatible_assignment]
2727
./generics_variance_inference.py:194:0: Incompatible assignment: expected generics_variance_inference.ShouldBeContravariant2[float | int], got generics_variance_inference.ShouldBeContravariant2[int] [incompatible_assignment]
28+
./generics_variance_inference.py:205:0: Incompatible assignment: expected generics_variance_inference.ShouldBeCovariant7[int], got generics_variance_inference.ShouldBeCovariant7[object] [incompatible_assignment]
2829
"""

‎conformance/results/pyrefly/generics_variance_inference.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ ERROR generics_variance_inference.py:169:31-58: `ShouldBeInvariant6[float]` is n
2626
ERROR generics_variance_inference.py:170:33-58: `ShouldBeInvariant6[int]` is not assignable to `ShouldBeInvariant6[float]` [bad-assignment]
2727
ERROR generics_variance_inference.py:181:31-58: `ShouldBeCovariant6[float]` is not assignable to `ShouldBeCovariant6[int]` [bad-assignment]
2828
ERROR generics_variance_inference.py:194:37-66: `ShouldBeContravariant2[int]` is not assignable to `ShouldBeContravariant2[float]` [bad-assignment]
29+
ERROR generics_variance_inference.py:205:31-59: `ShouldBeCovariant7[object]` is not assignable to `ShouldBeCovariant7[int]` [bad-assignment]
2930
"""

‎conformance/results/pyright/generics_variance_inference.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ generics_variance_inference.py:194:37 - error: Type "ShouldBeContravariant2[int]
7979
  "ShouldBeContravariant2[int]" is not assignable to "ShouldBeContravariant2[float]"
8080
    Type parameter "T@ShouldBeContravariant2" is contravariant, but "int" is not a supertype of "float"
8181
      "float" is not assignable to "int" (reportAssignmentType)
82+
generics_variance_inference.py:205:31 - error: Type "ShouldBeCovariant7[object]" is not assignable to declared type "ShouldBeCovariant7[int]"
83+
  "ShouldBeCovariant7[object]" is not assignable to "ShouldBeCovariant7[int]"
84+
    Type parameter "T@ShouldBeCovariant7" is covariant, but "object" is not a subtype of "int"
85+
      "object" is not assignable to "int" (reportAssignmentType)
8286
"""
8387
conformance_automated = "Pass"
8488
errors_diff = """

‎conformance/results/results.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,10 @@ <h3>Python Type System Conformance Test Results</h3>
520520
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_variance_inference</th>
521521
<th class="column col2 conformant">Pass</th>
522522
<th class="column col2 conformant">Pass</th>
523+
<th class="column col2 not-conformant">Unknown</th>
523524
<th class="column col2 conformant">Pass</th>
524525
<th class="column col2 conformant">Pass</th>
525-
<th class="column col2 conformant">Pass</th>
526-
<th class="column col2 conformant">Pass</th>
526+
<th class="column col2 not-conformant">Unknown</th>
527527
</tr>
528528
<tr><th class="column" colspan="7">
529529
<a class="test_group" href="https://typing.readthedocs.io/en/latest/spec/qualifiers.html">Type qualifiers</a>

‎conformance/results/ty/generics_variance_inference.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
conformance_automated = "Pass"
1+
conformance_automated = "Fail"
22
errors_diff = """
3+
Line 204: Unexpected errors ['generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]`']
34
"""
45
output = """
56
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
2526
generics_variance_inference.py:170:33: error[invalid-assignment] Object of type `ShouldBeInvariant6[int]` is not assignable to `ShouldBeInvariant6[int | float]`
2627
generics_variance_inference.py:181:31: error[invalid-assignment] Object of type `ShouldBeCovariant6[int | float]` is not assignable to `ShouldBeCovariant6[int]`
2728
generics_variance_inference.py:194:37: error[invalid-assignment] Object of type `ShouldBeContravariant2[int]` is not assignable to `ShouldBeContravariant2[int | float]`
29+
generics_variance_inference.py:204:34: error[invalid-assignment] Object of type `ShouldBeCovariant7[int]` is not assignable to `ShouldBeCovariant7[object]`
30+
generics_variance_inference.py:205:31: error[invalid-assignment] Object of type `ShouldBeCovariant7[object]` is not assignable to `ShouldBeCovariant7[int]`
2831
"""

‎conformance/results/zuban/generics_variance_inference.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
conformance_automated = "Pass"
1+
conformance_automated = "Fail"
22
errors_diff = """
3+
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]']
34
"""
45
output = """
56
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
2526
generics_variance_inference.py:170: error: Incompatible types in assignment (expression has type "ShouldBeInvariant6[int]", variable has type "ShouldBeInvariant6[float]") [assignment]
2627
generics_variance_inference.py:181: error: Incompatible types in assignment (expression has type "ShouldBeCovariant6[float]", variable has type "ShouldBeCovariant6[int]") [assignment]
2728
generics_variance_inference.py:194: error: Incompatible types in assignment (expression has type "ShouldBeContravariant2[int]", variable has type "ShouldBeContravariant2[float]") [assignment]
29+
generics_variance_inference.py:200: error: Name "S" is not defined [name-defined]
30+
generics_variance_inference.py:200: error: Name "S" is not defined [name-defined]
31+
generics_variance_inference.py:205: error: Incompatible types in assignment (expression has type "ShouldBeCovariant7[object]", variable has type "ShouldBeCovariant7[int]") [assignment]
2832
"""

‎conformance/tests/generics_variance_inference.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,14 @@ class ShouldBeContravariant2[T](Parent_Contravariant[T]):
192192

193193
c1: ShouldBeContravariant2[int] = ShouldBeContravariant2[float]() # OK
194194
c2: ShouldBeContravariant2[float] = ShouldBeContravariant2[int]() # E
195+
196+
class ShouldBeCovariant7[T]:
197+
def get(self) -> T:
198+
raise NotImplementedError
199+
200+
def add[S](self: "ShouldBeCovariant7[S]", other: list[S]) -> "ShouldBeCovariant7[S]":
201+
raise NotImplementedError
202+
203+
204+
d1: ShouldBeCovariant7[object] = ShouldBeCovariant7[int]() # OK
205+
d2: ShouldBeCovariant7[int] = ShouldBeCovariant7[object]() # E

0 commit comments

Comments
 (0)