Skip to content

Commit 02c4628

Browse files
committed
specify that type variable tuple should have variance
1 parent 495b5c9 commit 02c4628

14 files changed

Lines changed: 240 additions & 53 deletions

conformance/results/mypy/generics_typevartuple_basic.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ generics_typevartuple_basic.py:52: error: Free type variable expected in Generic
1010
generics_typevartuple_basic.py:53: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
1111
generics_typevartuple_basic.py:56: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
1212
generics_typevartuple_basic.py:59: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
13-
generics_typevartuple_basic.py:65: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
14-
generics_typevartuple_basic.py:66: error: Too many positional arguments for "TypeVarTuple" [misc]
15-
generics_typevartuple_basic.py:67: error: Unexpected keyword argument "bound" for "TypeVarTuple" [misc]
13+
generics_typevartuple_basic.py:65: error: Too many positional arguments for "TypeVarTuple" [misc]
14+
generics_typevartuple_basic.py:66: error: Unexpected keyword argument "bound" for "TypeVarTuple" [misc]
15+
generics_typevartuple_basic.py:99: error: Cannot infer value of type parameter "Shape" of "multiply" [misc]
1616
generics_typevartuple_basic.py:100: error: Cannot infer value of type parameter "Shape" of "multiply" [misc]
17-
generics_typevartuple_basic.py:101: error: Cannot infer value of type parameter "Shape" of "multiply" [misc]
18-
generics_typevartuple_basic.py:107: error: Can only use one type var tuple in a class def [misc]
17+
generics_typevartuple_basic.py:106: error: Free type variable expected in Generic[...] [misc]
18+
generics_typevartuple_basic.py:106: error: Name "Ts1" is not defined [name-defined]
1919
"""
2020
conformance_automated = "Fail"
2121
errors_diff = """
22-
Line 91: Expected 1 errors
22+
Line 90: Expected 1 errors
2323
"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 14: Expected 1 errors
5+
Line 34: Expected 1 errors
6+
Line 38: Expected 1 errors
7+
Line 45: Expected 1 errors
8+
Line 15: Unexpected errors ['generics_typevartuple_variance.py:15: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[object]", variable has type "ContravariantTypeVarTuple[int]") [assignment]']
9+
Line 27: Unexpected errors ['generics_typevartuple_variance.py:27: error: Unexpected keyword argument "contravariant" for "TypeVarTuple" [misc]']
10+
Line 39: Unexpected errors ['generics_typevartuple_variance.py:39: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTupleOld[object]", variable has type "ContravariantTypeVarTupleOld[int]") [assignment]']
11+
Line 41: Unexpected errors ['generics_typevartuple_variance.py:41: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]']
12+
"""
13+
output = """
14+
generics_typevartuple_variance.py:15: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTuple[object]", variable has type "ContravariantTypeVarTuple[int]") [assignment]
15+
generics_typevartuple_variance.py:23: error: Incompatible types in assignment (expression has type "CovariantTypeVarTuple[object]", variable has type "CovariantTypeVarTuple[int]") [assignment]
16+
generics_typevartuple_variance.py:27: error: Unexpected keyword argument "contravariant" for "TypeVarTuple" [misc]
17+
generics_typevartuple_variance.py:39: error: Incompatible types in assignment (expression has type "ContravariantTypeVarTupleOld[object]", variable has type "ContravariantTypeVarTupleOld[int]") [assignment]
18+
generics_typevartuple_variance.py:41: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
19+
generics_typevartuple_variance.py:52: error: Incompatible types in assignment (expression has type "CovariantTypeVarTupleOld[object]", variable has type "CovariantTypeVarTupleOld[int]") [assignment]
20+
"""

conformance/results/pyrefly/generics_typevartuple_basic.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ ERROR generics_typevartuple_basic.py:52:22-27: `TypeVarTuple` must be unpacked [
1010
ERROR generics_typevartuple_basic.py:53:37-42: `TypeVarTuple` must be unpacked [invalid-type-var-tuple]
1111
ERROR generics_typevartuple_basic.py:56:34-39: `TypeVarTuple` must be unpacked [invalid-type-var-tuple]
1212
ERROR generics_typevartuple_basic.py:59:24-29: `TypeVarTuple` must be unpacked [invalid-annotation]
13-
ERROR generics_typevartuple_basic.py:65:27-41: Unexpected keyword argument `covariant` to TypeVarTuple [invalid-type-var-tuple]
14-
ERROR generics_typevartuple_basic.py:66:27-30: Unexpected positional argument to TypeVarTuple [invalid-type-var-tuple]
15-
ERROR generics_typevartuple_basic.py:67:27-36: Unexpected keyword argument `bound` to TypeVarTuple [invalid-type-var-tuple]
16-
ERROR generics_typevartuple_basic.py:91:15-19: Argument `tuple[Literal[0]]` is not assignable to parameter `arg2` with type `tuple[int, int]` in function `func2` [bad-argument-type]
17-
ERROR generics_typevartuple_basic.py:100:17-18: Argument `Array[Width]` is not assignable to parameter `y` with type `Array[Height]` in function `multiply` [bad-argument-type]
18-
ERROR generics_typevartuple_basic.py:101:17-18: Argument `Array[Height, Width]` is not assignable to parameter `y` with type `Array[Height]` in function `multiply` [bad-argument-type]
19-
ERROR generics_typevartuple_basic.py:107:7-13: Type parameters for class may not have more than one TypeVarTuple [invalid-type-var-tuple]
13+
ERROR generics_typevartuple_basic.py:65:27-30: Unexpected positional argument to TypeVarTuple [invalid-type-var-tuple]
14+
ERROR generics_typevartuple_basic.py:66:27-36: Unexpected keyword argument `bound` to TypeVarTuple [invalid-type-var-tuple]
15+
ERROR generics_typevartuple_basic.py:90:15-19: Argument `tuple[Literal[0]]` is not assignable to parameter `arg2` with type `tuple[int, int]` in function `func2` [bad-argument-type]
16+
ERROR generics_typevartuple_basic.py:99:17-18: Argument `Array[Width]` is not assignable to parameter `y` with type `Array[Height]` in function `multiply` [bad-argument-type]
17+
ERROR generics_typevartuple_basic.py:100:17-18: Argument `Array[Height, Width]` is not assignable to parameter `y` with type `Array[Height]` in function `multiply` [bad-argument-type]
18+
ERROR generics_typevartuple_basic.py:106:22-26: Expected a type form, got instance of `*Unknown` [not-a-type]
19+
ERROR generics_typevartuple_basic.py:106:23-26: Could not find name `Ts1` [unknown-name]
2020
"""
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 34: Expected 1 errors
5+
Line 45: Expected 1 errors
6+
Line 15: Unexpected errors ['`ContravariantTypeVarTuple[object]` is not assignable to `ContravariantTypeVarTuple[int]` [bad-assignment]']
7+
Line 24: Unexpected errors ['`CovariantTypeVarTuple[int]` is not assignable to `CovariantTypeVarTuple[object]` [bad-assignment]']
8+
Line 27: Unexpected errors ['Unexpected keyword argument `contravariant` to TypeVarTuple [invalid-type-var-tuple]']
9+
Line 39: Unexpected errors ['`ContravariantTypeVarTupleOld[object]` is not assignable to `ContravariantTypeVarTupleOld[int]` [bad-assignment]']
10+
Line 41: Unexpected errors ['Unexpected keyword argument `covariant` to TypeVarTuple [invalid-type-var-tuple]']
11+
Line 53: Unexpected errors ['`CovariantTypeVarTupleOld[int]` is not assignable to `CovariantTypeVarTupleOld[object]` [bad-assignment]']
12+
"""
13+
output = """
14+
ERROR generics_typevartuple_variance.py:14:45-77: `ContravariantTypeVarTuple[int]` is not assignable to `ContravariantTypeVarTuple[object]` [bad-assignment]
15+
ERROR generics_typevartuple_variance.py:15:42-77: `ContravariantTypeVarTuple[object]` is not assignable to `ContravariantTypeVarTuple[int]` [bad-assignment]
16+
ERROR generics_typevartuple_variance.py:23:39-70: `CovariantTypeVarTuple[object]` is not assignable to `CovariantTypeVarTuple[int]` [bad-assignment]
17+
ERROR generics_typevartuple_variance.py:24:42-70: `CovariantTypeVarTuple[int]` is not assignable to `CovariantTypeVarTuple[object]` [bad-assignment]
18+
ERROR generics_typevartuple_variance.py:27:29-47: Unexpected keyword argument `contravariant` to TypeVarTuple [invalid-type-var-tuple]
19+
ERROR generics_typevartuple_variance.py:38:52-87: `ContravariantTypeVarTupleOld[int]` is not assignable to `ContravariantTypeVarTupleOld[object]` [bad-assignment]
20+
ERROR generics_typevartuple_variance.py:39:49-87: `ContravariantTypeVarTupleOld[object]` is not assignable to `ContravariantTypeVarTupleOld[int]` [bad-assignment]
21+
ERROR generics_typevartuple_variance.py:41:31-45: Unexpected keyword argument `covariant` to TypeVarTuple [invalid-type-var-tuple]
22+
ERROR generics_typevartuple_variance.py:52:46-80: `CovariantTypeVarTupleOld[object]` is not assignable to `CovariantTypeVarTupleOld[int]` [bad-assignment]
23+
ERROR generics_typevartuple_variance.py:53:49-80: `CovariantTypeVarTupleOld[int]` is not assignable to `CovariantTypeVarTupleOld[object]` [bad-assignment]
24+
"""

conformance/results/pyright/generics_typevartuple_basic.toml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Does not correctly solve TypeVarTuple with heterogeneous bounds.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
7-
Line 90: Unexpected errors ['generics_typevartuple_basic.py:90:14 - error: Argument of type "tuple[Literal[\\'0\\']]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"']
7+
Line 89: Unexpected errors ['generics_typevartuple_basic.py:89:14 - error: Argument of type "tuple[Literal[\\'0\\']]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"']
88
"""
99
output = """
1010
generics_typevartuple_basic.py:42:34 - error: Argument of type "Height" cannot be assigned to parameter "shape" of type "tuple[*Shape@Array]" in function "__init__"
@@ -19,21 +19,20 @@ generics_typevartuple_basic.py:52:22 - error: Expected unpacked TypeVarTuple; us
1919
generics_typevartuple_basic.py:53:37 - error: Expected unpacked TypeVarTuple; use Unpack[Shape] or *Shape (reportInvalidTypeForm)
2020
generics_typevartuple_basic.py:56:34 - error: Expected unpacked TypeVarTuple; use Unpack[Shape] or *Shape (reportInvalidTypeForm)
2121
generics_typevartuple_basic.py:59:24 - error: Expected unpacked TypeVarTuple; use Unpack[Shape] or *Shape (reportInvalidTypeForm)
22-
generics_typevartuple_basic.py:65:27 - error: "covariant" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)
23-
generics_typevartuple_basic.py:66:27 - error: TypeVarTuple cannot have value constraints (reportGeneralTypeIssues)
24-
generics_typevartuple_basic.py:66:32 - error: TypeVarTuple cannot have value constraints (reportGeneralTypeIssues)
25-
generics_typevartuple_basic.py:67:27 - error: "bound" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)
26-
generics_typevartuple_basic.py:90:14 - error: Argument of type "tuple[Literal['0']]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
22+
generics_typevartuple_basic.py:65:27 - error: TypeVarTuple cannot have value constraints (reportGeneralTypeIssues)
23+
generics_typevartuple_basic.py:65:32 - error: TypeVarTuple cannot have value constraints (reportGeneralTypeIssues)
24+
generics_typevartuple_basic.py:66:27 - error: "bound" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)
25+
generics_typevartuple_basic.py:89:14 - error: Argument of type "tuple[Literal['0']]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
2726
  "Literal['0']" is not assignable to "int" (reportArgumentType)
28-
generics_typevartuple_basic.py:91:15 - error: Argument of type "tuple[Literal[0]]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
27+
generics_typevartuple_basic.py:90:15 - error: Argument of type "tuple[Literal[0]]" cannot be assigned to parameter "arg2" of type "tuple[*Ts@func2]" in function "func2"
2928
  "tuple[Literal[0]]" is not assignable to "tuple[int, int]"
3029
    Tuple size mismatch; expected 2 but received 1 (reportArgumentType)
31-
generics_typevartuple_basic.py:100:17 - error: Argument of type "Array[Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
30+
generics_typevartuple_basic.py:99:17 - error: Argument of type "Array[Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
3231
  "Array[Width]" is not assignable to "Array[Height]"
3332
    Type parameter "Shape@Array" is invariant, but "*tuple[Width]" is not the same as "*tuple[Height]" (reportArgumentType)
34-
generics_typevartuple_basic.py:101:17 - error: Argument of type "Array[Height, Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
33+
generics_typevartuple_basic.py:100:17 - error: Argument of type "Array[Height, Width]" cannot be assigned to parameter "y" of type "Array[*Shape@multiply]" in function "multiply"
3534
  "Array[Height, Width]" is not assignable to "Array[Height]"
3635
    Type parameter "Shape@Array" is invariant, but "*tuple[Height, Width]" is not the same as "*tuple[Height]" (reportArgumentType)
37-
generics_typevartuple_basic.py:107:14 - error: Generic class can have at most one TypeVarTuple type parameter but received multiple ("Ts1", "Ts2") (reportGeneralTypeIssues)
38-
generics_typevartuple_basic.py:107:29 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple (reportInvalidTypeForm)
36+
generics_typevartuple_basic.py:106:23 - error: "Ts1" is not defined (reportUndefinedVariable)
37+
generics_typevartuple_basic.py:106:23 - error: Type argument for "Generic" must be a type variable (reportInvalidTypeForm)
3938
"""
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
conformant = "Unsupported"
2+
conformance_automated = "Fail"
3+
errors_diff = """
4+
Line 34: Expected 1 errors
5+
Line 45: Expected 1 errors
6+
Line 15: Unexpected errors ['generics_typevartuple_variance.py:15:42 - error: Type "ContravariantTypeVarTuple[object]" is not assignable to declared type "ContravariantTypeVarTuple[int]"']
7+
Line 24: Unexpected errors ['generics_typevartuple_variance.py:24:42 - error: Type "CovariantTypeVarTuple[int]" is not assignable to declared type "CovariantTypeVarTuple[object]"']
8+
Line 27: Unexpected errors ['generics_typevartuple_variance.py:27:29 - error: "contravariant" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)']
9+
Line 39: Unexpected errors ['generics_typevartuple_variance.py:39:49 - error: Type "ContravariantTypeVarTupleOld[object]" is not assignable to declared type "ContravariantTypeVarTupleOld[int]"']
10+
Line 41: Unexpected errors ['generics_typevartuple_variance.py:41:31 - error: "covariant" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)']
11+
Line 53: Unexpected errors ['generics_typevartuple_variance.py:53:49 - error: Type "CovariantTypeVarTupleOld[int]" is not assignable to declared type "CovariantTypeVarTupleOld[object]"']
12+
"""
13+
output = """
14+
generics_typevartuple_variance.py:14:45 - error: Type "ContravariantTypeVarTuple[int]" is not assignable to declared type "ContravariantTypeVarTuple[object]"
15+
  "ContravariantTypeVarTuple[int]" is not assignable to "ContravariantTypeVarTuple[object]"
16+
    Type parameter "InTs@ContravariantTypeVarTuple" is invariant, but "*tuple[int]" is not the same as "*tuple[object]" (reportAssignmentType)
17+
generics_typevartuple_variance.py:15:42 - error: Type "ContravariantTypeVarTuple[object]" is not assignable to declared type "ContravariantTypeVarTuple[int]"
18+
  "ContravariantTypeVarTuple[object]" is not assignable to "ContravariantTypeVarTuple[int]"
19+
    Type parameter "InTs@ContravariantTypeVarTuple" is invariant, but "*tuple[object]" is not the same as "*tuple[int]" (reportAssignmentType)
20+
generics_typevartuple_variance.py:23:39 - error: Type "CovariantTypeVarTuple[object]" is not assignable to declared type "CovariantTypeVarTuple[int]"
21+
  "CovariantTypeVarTuple[object]" is not assignable to "CovariantTypeVarTuple[int]"
22+
    Type parameter "OutTs@CovariantTypeVarTuple" is invariant, but "*tuple[object]" is not the same as "*tuple[int]" (reportAssignmentType)
23+
generics_typevartuple_variance.py:24:42 - error: Type "CovariantTypeVarTuple[int]" is not assignable to declared type "CovariantTypeVarTuple[object]"
24+
  "CovariantTypeVarTuple[int]" is not assignable to "CovariantTypeVarTuple[object]"
25+
    Type parameter "OutTs@CovariantTypeVarTuple" is invariant, but "*tuple[int]" is not the same as "*tuple[object]" (reportAssignmentType)
26+
generics_typevartuple_variance.py:27:29 - error: "contravariant" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)
27+
generics_typevartuple_variance.py:38:52 - error: Type "ContravariantTypeVarTupleOld[int]" is not assignable to declared type "ContravariantTypeVarTupleOld[object]"
28+
  "ContravariantTypeVarTupleOld[int]" is not assignable to "ContravariantTypeVarTupleOld[object]"
29+
    Type parameter "InTs@ContravariantTypeVarTupleOld" is invariant, but "*tuple[int]" is not the same as "*tuple[object]" (reportAssignmentType)
30+
generics_typevartuple_variance.py:39:49 - error: Type "ContravariantTypeVarTupleOld[object]" is not assignable to declared type "ContravariantTypeVarTupleOld[int]"
31+
  "ContravariantTypeVarTupleOld[object]" is not assignable to "ContravariantTypeVarTupleOld[int]"
32+
    Type parameter "InTs@ContravariantTypeVarTupleOld" is invariant, but "*tuple[object]" is not the same as "*tuple[int]" (reportAssignmentType)
33+
generics_typevartuple_variance.py:41:31 - error: "covariant" is unknown parameter to TypeVarTuple (reportGeneralTypeIssues)
34+
generics_typevartuple_variance.py:52:46 - error: Type "CovariantTypeVarTupleOld[object]" is not assignable to declared type "CovariantTypeVarTupleOld[int]"
35+
  "CovariantTypeVarTupleOld[object]" is not assignable to "CovariantTypeVarTupleOld[int]"
36+
    Type parameter "OutTs@CovariantTypeVarTupleOld" is invariant, but "*tuple[object]" is not the same as "*tuple[int]" (reportAssignmentType)
37+
generics_typevartuple_variance.py:53:49 - error: Type "CovariantTypeVarTupleOld[int]" is not assignable to declared type "CovariantTypeVarTupleOld[object]"
38+
  "CovariantTypeVarTupleOld[int]" is not assignable to "CovariantTypeVarTupleOld[object]"
39+
    Type parameter "OutTs@CovariantTypeVarTupleOld" is invariant, but "*tuple[int]" is not the same as "*tuple[object]" (reportAssignmentType)
40+
"""

conformance/results/results.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ <h3>Python Type System Conformance Test Results</h3>
468468
<th class="column col2 conformant">Pass</th>
469469
<th class="column col2 not-conformant">Unsupported</th>
470470
</tr>
471+
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_typevartuple_variance</th>
472+
<th class="column col2 not-conformant">Unsupported</th>
473+
<th class="column col2 not-conformant">Unsupported</th>
474+
<th class="column col2 not-conformant">Unsupported</th>
475+
<th class="column col2 not-conformant">Unsupported</th>
476+
<th class="column col2 not-conformant">Unsupported</th>
477+
</tr>
471478
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_upper_bound</th>
472479
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject use of type variable within an upper bound.</p></span></div></th>
473480
<th class="column col2 conformant">Pass</th>

0 commit comments

Comments
 (0)