Skip to content

Commit 56ffa79

Browse files
spec: do not mandate inference details around TypeVarTuple (#2203)
I don't think this case should error; a type checker can solve Ts to something like (object,) or (int | str,). This is not all that different from the first call to func4(), where the two calls with (0,) and (1,) lead to Ts being solved to a common supertype.
1 parent 859d3d3 commit 56ffa79

14 files changed

+62
-63
lines changed

conformance/results/mypy/generics_typevartuple_args.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
conformant = "Partial"
22
notes = """
3-
Does not enforce that tuples captured by TypeVarTuple are same type.
3+
Does not enforce that tuples captured by TypeVarTuple are of the same length.
44
"""
55
output = """
66
generics_typevartuple_args.py:33: error: Argument 3 to "exec_le" has incompatible type "str"; expected "Env" [arg-type]
@@ -15,5 +15,4 @@ generics_typevartuple_args.py:67: error: Too few arguments for "func3" [call-ar
1515
conformance_automated = "Fail"
1616
errors_diff = """
1717
Line 75: Expected 1 errors
18-
Line 76: Expected 1 errors
1918
"""
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
conformant = "Partial"
22
notes = """
33
Does not enforce that tuples captured by TypeVarTuple are same length.
4-
Does not enforce that tuples captured by TypeVarTuple are same type.
54
"""
65
output = """
76
generics_typevartuple_basic.py:42: error: Argument 1 to "Array" has incompatible type "Height"; expected "tuple[Height, Width]" [arg-type]
@@ -10,7 +9,6 @@ generics_typevartuple_basic.py:45: error: Argument 1 to "Array" has incompatible
109
generics_typevartuple_basic.py:52: error: Free type variable expected in Generic[...] [misc]
1110
generics_typevartuple_basic.py:53: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
1211
generics_typevartuple_basic.py:56: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
13-
generics_typevartuple_basic.py:57: error: Incompatible return value type (got "tuple[*Shape]", expected "tuple[Any]") [return-value]
1412
generics_typevartuple_basic.py:59: error: TypeVarTuple "Shape" is only valid with an unpack [valid-type]
1513
generics_typevartuple_basic.py:65: error: Unexpected keyword argument "covariant" for "TypeVarTuple" [misc]
1614
generics_typevartuple_basic.py:66: error: Too many positional arguments for "TypeVarTuple" [misc]
@@ -21,7 +19,5 @@ generics_typevartuple_basic.py:106: error: Can only use one type var tuple in a
2119
"""
2220
conformance_automated = "Fail"
2321
errors_diff = """
24-
Line 89: Expected 1 errors
2522
Line 90: Expected 1 errors
26-
Line 57: Unexpected errors ['generics_typevartuple_basic.py:57: error: Incompatible return value type (got "tuple[*Shape]", expected "tuple[Any]") [return-value]']
2723
"""

conformance/results/pyrefly/generics_typevartuple_args.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
conformant = "Pass"
2-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
conformance_automated = "Fail"
3+
notes = """
4+
Does not correctly solve TypeVarTuple with heterogeneous bounds.
5+
"""
36
errors_diff = """
7+
Line 76: Unexpected errors ["Argument `tuple[Literal['1']]` is not assignable to parameter `*args` with type `tuple[int]` in function `func4` [bad-argument-type]"]
48
"""
59
output = """
610
ERROR generics_typevartuple_args.py:33:12-23: Unpacked argument `tuple[Literal[0], Literal['']]` is not assignable to parameter `*args` with type `tuple[*@_, Env]` in function `exec_le` [bad-argument-type]

conformance/results/pyrefly/generics_typevartuple_basic.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
conformant = "Partial"
22
notes = """
3-
TypeVarTuple is pinned too early when calling generic function
3+
TypeVarTuple is pinned too early when calling generic function.
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
77
Line 85: Unexpected errors ['Argument `tuple[float]` is not assignable to parameter `arg2` with type `tuple[int]` in function `func2` [bad-argument-type]']
8+
Line 89: Unexpected errors ["Argument `tuple[Literal['0']]` is not assignable to parameter `arg2` with type `tuple[int]` in function `func2` [bad-argument-type]"]
89
"""
910
output = """
1011
ERROR generics_typevartuple_basic.py:42:34-43: Argument `Height` is not assignable to parameter `shape` with type `tuple[Height, Width]` in function `Array.__init__` [bad-argument-type]

conformance/results/pyright/generics_typevartuple_args.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not correctly solve TypeVarTuple with heterogeneous bounds.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
7+
Line 76: Unexpected errors ['generics_typevartuple_args.py:76:14 - error: Argument of type "tuple[Literal[\\'1\\']]" cannot be assigned to parameter "args" of type "tuple[*Ts@func4]" in function "func4"']
8+
"""
29
output = """
310
generics_typevartuple_args.py:33:20 - error: Argument of type "Literal['']" cannot be assigned to parameter of type "Env" in function "exec_le"
411
  "Literal['']" is not assignable to "Env" (reportArgumentType)
@@ -17,6 +24,3 @@ generics_typevartuple_args.py:75:13 - error: Argument of type "tuple[Literal[1],
1724
generics_typevartuple_args.py:76:14 - error: Argument of type "tuple[Literal['1']]" cannot be assigned to parameter "args" of type "tuple[*Ts@func4]" in function "func4"
1825
  "Literal['1']" is not assignable to "int" (reportArgumentType)
1926
"""
20-
conformance_automated = "Pass"
21-
errors_diff = """
22-
"""

conformance/results/pyright/generics_typevartuple_basic.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
conformant = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not correctly solve TypeVarTuple with heterogeneous bounds.
4+
"""
5+
conformance_automated = "Fail"
6+
errors_diff = """
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"']
8+
"""
29
output = """
310
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__"
411
  "Height" is not assignable to "tuple[*Shape@Array]" (reportArgumentType)
@@ -30,6 +37,3 @@ generics_typevartuple_basic.py:100:17 - error: Argument of type "Array[Height, W
3037
generics_typevartuple_basic.py:106:14 - error: Generic class can have at most one TypeVarTuple type parameter but received multiple ("Ts1", "Ts2") (reportGeneralTypeIssues)
3138
generics_typevartuple_basic.py:106:29 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple (reportInvalidTypeForm)
3239
"""
33-
conformance_automated = "Pass"
34-
errors_diff = """
35-
"""

conformance/results/results.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -413,17 +413,17 @@ <h3>Python Type System Conformance Test Results</h3>
413413
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not reject access of generic instance variable from the class object.</p></span></div></th>
414414
</tr>
415415
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_typevartuple_args</th>
416-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not enforce that tuples captured by TypeVarTuple are same type.</p></span></div></th>
417-
<th class="column col2 conformant">Pass</th>
418-
<th class="column col2 conformant">Pass</th>
419-
<th class="column col2 conformant">Pass</th>
416+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not enforce that tuples captured by TypeVarTuple are of the same length.</p></span></div></th>
417+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not correctly solve TypeVarTuple with heterogeneous bounds.</p></span></div></th>
418+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not correctly solve TypeVarTuple with heterogeneous bounds.</p></span></div></th>
419+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not correctly solve TypeVarTuple with heterogeneous bounds.</p></span></div></th>
420420
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Supports PEP-646 unpacked tuples but not TypeVarTuple.</p></span></div></th>
421421
</tr>
422422
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_typevartuple_basic</th>
423-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not enforce that tuples captured by TypeVarTuple are same length.</p><p>Does not enforce that tuples captured by TypeVarTuple are same type.</p></span></div></th>
424-
<th class="column col2 conformant">Pass</th>
425-
<th class="column col2 conformant">Pass</th>
426-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>TypeVarTuple is pinned too early when calling generic function</p></span></div></th>
423+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not enforce that tuples captured by TypeVarTuple are same length.</p></span></div></th>
424+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not correctly solve TypeVarTuple with heterogeneous bounds.</p></span></div></th>
425+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not correctly solve TypeVarTuple with heterogeneous bounds.</p></span></div></th>
426+
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>TypeVarTuple is pinned too early when calling generic function.</p></span></div></th>
427427
<th class="column col2 not-conformant">Unsupported</th>
428428
</tr>
429429
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_typevartuple_callable</th>

conformance/results/ty/generics_typevartuple_args.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Line 58: Expected 1 errors
1212
Line 59: Expected 1 errors
1313
Line 67: Expected 1 errors
1414
Line 75: Expected 1 errors
15-
Line 76: Expected 1 errors
1615
Line 29: Unexpected errors ['generics_typevartuple_args.py:29:5: error[type-assertion-failure] Type `tuple[@Todo(TypeVarTuple), ...]` does not match asserted type `tuple[int, str]`']
1716
Line 31: Unexpected errors ['generics_typevartuple_args.py:31:5: error[type-assertion-failure] Type `tuple[@Todo(TypeVarTuple), ...]` does not match asserted type `tuple[()]`']
1817
Line 32: Unexpected errors ['generics_typevartuple_args.py:32:5: error[type-assertion-failure] Type `tuple[@Todo(TypeVarTuple), ...]` does not match asserted type `tuple[int, str]`']

conformance/results/ty/generics_typevartuple_basic.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Line 43: Expected 1 errors
55
Line 53: Expected 1 errors
66
Line 56: Expected 1 errors
77
Line 59: Expected 1 errors
8-
Line 89: Expected 1 errors
98
Line 90: Expected 1 errors
109
Line 99: Expected 1 errors
1110
Line 100: Expected 1 errors

conformance/results/zuban/generics_typevartuple_args.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
conformance_automated = "Pass"
1+
conformant = "Partial"
2+
notes = """
3+
Does not correctly solve TypeVarTuple with heterogeneous bounds.
4+
"""
5+
conformance_automated = "Fail"
26
errors_diff = """
7+
Line 76: Unexpected errors ['generics_typevartuple_args.py:76: error: Argument 2 to "func4" has incompatible type "tuple[Literal[\\'1\\']]"; expected "tuple[int]" [arg-type]']
38
"""
49
output = """
510
generics_typevartuple_args.py:33: error: Argument 3 to "exec_le" has incompatible type "str"; expected "Env" [arg-type]

0 commit comments

Comments
 (0)