Skip to content

Commit 6b1a64c

Browse files
Allow type checkers to infer more precise types for tuples (#2194)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent e9fccc9 commit 6b1a64c

13 files changed

+37
-39
lines changed

conformance/results/pyrefly/aliases_explicit.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ errors_diff = """
44
"""
55
output = """
66
ERROR aliases_explicit.py:67:9-28: `TypeAlias[GoodTypeAlias2, type[int | None]]` is not subscriptable [unsupported-operation]
7-
ERROR aliases_explicit.py:68:9-28: `TypeAlias[GoodTypeAlias3, type[list[GoodTypeAlias2]]]` is not subscriptable [unsupported-operation]
7+
ERROR aliases_explicit.py:68:9-28: `TypeAlias[GoodTypeAlias3, type[list[int | None]]]` is not subscriptable [unsupported-operation]
88
ERROR aliases_explicit.py:69:9-33: Expected 1 type argument for `GoodTypeAlias4`, got 2 [bad-specialization]
99
ERROR aliases_explicit.py:70:9-33: Expected 1 type argument for `GoodTypeAlias8`, got 2 [bad-specialization]
1010
ERROR aliases_explicit.py:71:9-33: Expected a valid ParamSpec expression, got `int` [invalid-param-spec]

conformance/results/pyrefly/aliases_recursive.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ ERROR aliases_recursive.py:63:30-43: `list[list[float] | str | GenericTypeAlias1
1414
ERROR aliases_recursive.py:69:35-64: `list[int | list[int | list[int | list[float] | str | GenericTypeAlias2[str, int]] | str | GenericTypeAlias2[str, int]] | str | GenericTypeAlias2[str, int]]` is not assignable to `list[int | str | GenericTypeAlias2[str, int]]` [bad-assignment]
1515
ERROR aliases_recursive.py:72:29-57: Found cyclic self-reference in `RecursiveUnion` [invalid-type-alias]
1616
ERROR aliases_recursive.py:75:31-61: Found cyclic self-reference in `MutualReference1` [invalid-type-alias]
17+
ERROR aliases_recursive.py:75:93-123: Found cyclic self-reference in `MutualReference2` [invalid-type-alias]
1718
"""

conformance/results/pyrefly/aliases_type_statement.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ ERROR aliases_type_statement.py:77:7-41: `str` is not assignable to upper bound
3131
ERROR aliases_type_statement.py:79:7-41: `int` is not assignable to upper bound `str` of type variable `T` [bad-specialization]
3232
ERROR aliases_type_statement.py:82:28-47: Found cyclic self-reference in `RecursiveTypeAlias3` [invalid-type-alias]
3333
ERROR aliases_type_statement.py:84:31-59: Found cyclic self-reference in `RecursiveTypeAlias4` [invalid-type-alias]
34+
ERROR aliases_type_statement.py:88:28-47: Found cyclic self-reference in `RecursiveTypeAlias6` [invalid-type-alias]
3435
ERROR aliases_type_statement.py:89:28-47: Found cyclic self-reference in `RecursiveTypeAlias7` [invalid-type-alias]
3536
"""
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
conformant = "Partial"
2-
notes = """
3-
Does not detect circular definitions.
4-
"""
5-
conformance_automated = "Fail"
1+
conformance_automated = "Pass"
62
errors_diff = """
7-
Line 48: Expected 1 errors
8-
Line 66: Expected 1 errors
93
"""
104
output = """
115
ERROR aliases_typealiastype.py:32:7-30: Object of class `TypeAliasType` has no attribute `other_attrib` [missing-attribute]
126
ERROR aliases_typealiastype.py:40:5-30: `int` is not assignable to upper bound `str` of type variable `TStr` [bad-specialization]
137
ERROR aliases_typealiastype.py:43:13-66: Type variable `S` is out of scope for this `TypeAliasType` [invalid-type-alias]
148
ERROR aliases_typealiastype.py:44:13-48: Type variable `S` is out of scope for this `TypeAliasType` [invalid-type-alias]
159
ERROR aliases_typealiastype.py:45:45-65: Value for argument `type_params` must be a tuple literal [invalid-type-alias]
16-
ERROR aliases_typealiastype.py:46:41-50: Found cyclic self-reference in `BadAlias4` [invalid-type-alias]
17-
ERROR aliases_typealiastype.py:47:40-60: Found cyclic self-reference in `BadAlias5` [invalid-type-alias]
18-
ERROR aliases_typealiastype.py:49:40-49: Found cyclic self-reference in `BadAlias7` [invalid-type-alias]
10+
ERROR aliases_typealiastype.py:46:13-52: Found cyclic self-reference in `BadAlias4` [invalid-type-alias]
11+
ERROR aliases_typealiastype.py:47:13-79: Found cyclic self-reference in `BadAlias5` [invalid-type-alias]
12+
ERROR aliases_typealiastype.py:48:13-52: Found cyclic self-reference in `BadAlias6` [invalid-type-alias]
13+
ERROR aliases_typealiastype.py:49:13-50: Found cyclic self-reference in `BadAlias7` [invalid-type-alias]
1914
ERROR aliases_typealiastype.py:52:40-80: Function call cannot be used in annotations [invalid-annotation]
2015
ERROR aliases_typealiastype.py:53:40-50: List literal cannot be used in annotations [invalid-annotation]
2116
ERROR aliases_typealiastype.py:54:42-55: Tuple literal cannot be used in annotations [invalid-annotation]
@@ -31,4 +26,5 @@ ERROR aliases_typealiastype.py:61:42-46: Bool literal cannot be used in annotati
3126
ERROR aliases_typealiastype.py:62:42-43: Number literal cannot be used in annotations [invalid-annotation]
3227
ERROR aliases_typealiastype.py:63:42-53: Boolean operation cannot be used in annotations [invalid-annotation]
3328
ERROR aliases_typealiastype.py:64:42-52: F-string cannot be used in annotations [invalid-annotation]
29+
ERROR aliases_typealiastype.py:66:14-59: Found cyclic self-reference in `BadAlias21` [invalid-type-alias]
3430
"""

conformance/results/pyrefly/generics_scoping.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ Does not implement several scoping checks/restrictions for generics
44
"""
55
conformance_automated = "Fail"
66
errors_diff = """
7-
Line 61: Expected 1 errors
8-
Line 65: Expected 1 errors
97
Line 86: Expected 1 errors
108
Line 89: Expected 1 errors
119
Line 98: Expected 1 errors
12-
Line 105: Expected 1 errors
13-
Line 106: Expected 1 errors
1410
Line 107: Expected 1 errors
1511
"""
1612
output = """
@@ -19,5 +15,9 @@ ERROR generics_scoping.py:20:12-38: assert_type(str, Literal['a']) failed [asser
1915
ERROR generics_scoping.py:34:10-13: Argument `Literal['a']` is not assignable to parameter `x` with type `int` in function `MyClass.meth_2` [bad-argument-type]
2016
ERROR generics_scoping.py:50:12-48: assert_type(str, Literal['abc']) failed [assert-type]
2117
ERROR generics_scoping.py:54:12-50: assert_type(bytes, Literal[b'abc']) failed [assert-type]
18+
ERROR generics_scoping.py:61:8-15: Type variable `S` is not in scope [invalid-type-var]
19+
ERROR generics_scoping.py:65:14-21: Type variable `S` is not in scope [invalid-type-var]
2220
ERROR generics_scoping.py:76:11-20: Redundant type parameter declaration [invalid-type-var]
21+
ERROR generics_scoping.py:105:14-15: Type variable `T` is not in scope [invalid-type-var]
22+
ERROR generics_scoping.py:106:14-21: Type variable `T` is not in scope [invalid-type-var]
2323
"""

conformance/results/pyrefly/generics_typevartuple_args.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ conformance_automated = "Pass"
33
errors_diff = """
44
"""
55
output = """
6-
ERROR generics_typevartuple_args.py:33:8-19: Unpacked argument `tuple[Literal[0], Literal['']]` is not assignable to parameter `*args` with type `tuple[*@_, Env]` in function `exec_le` [bad-argument-type]
7-
ERROR generics_typevartuple_args.py:34:8-30: Unpacked argument `tuple[Literal[0], Literal['']]` is not assignable to parameter `*args` with type `tuple[*@_, Env]` in function `exec_le` [bad-argument-type]
6+
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]
7+
ERROR generics_typevartuple_args.py:34:12-34: Unpacked argument `tuple[Literal[0], Literal['']]` is not assignable to parameter `*args` with type `tuple[*@_, Env]` in function `exec_le` [bad-argument-type]
88
ERROR generics_typevartuple_args.py:48:6-17: Unpacked argument `tuple[Literal[1], Literal['2'], Literal[3]]` is not assignable to parameter `*args` with type `tuple[int, ...]` in function `func1` [bad-argument-type]
99
ERROR generics_typevartuple_args.py:57:6-16: Unpacked argument `tuple[Literal[1], Literal[1], Literal['']]` is not assignable to parameter `*args` with type `tuple[int, *tuple[str, ...], str]` in function `func2` [bad-argument-type]
1010
ERROR generics_typevartuple_args.py:58:6-9: Unpacked argument `tuple[Literal[1]]` is not assignable to parameter `*args` with type `tuple[int, *tuple[str, ...], str]` in function `func2` [bad-argument-type]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version = "pyrefly 0.53.0"
1+
version = "pyrefly 0.54.0"

conformance/results/pyright/generics_typevartuple_args.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
conformant = "Pass"
22
output = """
3-
generics_typevartuple_args.py:33:16 - error: Argument of type "Literal['']" cannot be assigned to parameter of type "Env" in function "exec_le"
3+
generics_typevartuple_args.py:33:20 - error: Argument of type "Literal['']" cannot be assigned to parameter of type "Env" in function "exec_le"
44
  "Literal['']" is not assignable to "Env" (reportArgumentType)
5-
generics_typevartuple_args.py:34:16 - error: Argument of type "Literal['']" cannot be assigned to parameter of type "Env" in function "exec_le"
5+
generics_typevartuple_args.py:34:20 - error: Argument of type "Literal['']" cannot be assigned to parameter of type "Env" in function "exec_le"
66
  "Literal['']" is not assignable to "Env" (reportArgumentType)
77
generics_typevartuple_args.py:48:10 - error: Argument of type "Literal['2']" cannot be assigned to parameter of type "int" in function "func1"
88
  "Literal['2']" is not assignable to "int" (reportArgumentType)

conformance/results/results.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,9 @@ <h3>Python Type System Conformance Test Results</h3>
176176
</th>
177177
<th class='tc-header'><div class='tc-name'>pyright 1.1.408</div>
178178
</th>
179-
<th class='tc-header'><div class='tc-name'>zuban 0.6.0</div>
179+
<th class='tc-header'><div class='tc-name'>zuban 0.6.1</div>
180180
</th>
181-
<th class='tc-header'><div class='tc-name'>pyrefly 0.53.0</div>
181+
<th class='tc-header'><div class='tc-name'>pyrefly 0.54.0</div>
182182
</th>
183183
</tr>
184184
<tr><th class="column" colspan="5">
@@ -307,7 +307,7 @@ <h3>Python Type System Conformance Test Results</h3>
307307
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_scoping</th>
308308
<th class="column col2 conformant">Pass</th>
309309
<th class="column col2 conformant">Pass</th>
310-
<th class="column col2 partially-conformant">Partial</th>
310+
<th class="column col2 conformant">Pass</th>
311311
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not implement several scoping checks/restrictions for generics</p></span></div></th>
312312
</tr>
313313
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;generics_self_advanced</th>
@@ -503,7 +503,7 @@ <h3>Python Type System Conformance Test Results</h3>
503503
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Incorrectly rejects some recursive type aliases using TypeAliasType.</p><p>Incorrectly rejects the use of a class-scoped TypeVar in a TypeAliasType definition.</p></span></div></th>
504504
<th class="column col2 conformant">Pass</th>
505505
<th class="column col2 conformant">Pass</th>
506-
<th class="column col2 partially-conformant"><div class="hover-text">Partial<span class="tooltip-text" id="bottom"><p>Does not detect circular definitions.</p></span></div></th>
506+
<th class="column col2 conformant">Pass</th>
507507
</tr>
508508
<tr><th class="column col1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aliases_variance</th>
509509
<th class="column col2 conformant">Pass</th>

conformance/results/zuban/generics_scoping.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
conformance_automated = "Fail"
2-
conformant = "Partial"
1+
conformance_automated = "Pass"
32
errors_diff = """
4-
Lines 15, 16: Expected error (tag 'fun1')
5-
Lines 19, 20: Expected error (tag 'fun2')
6-
Lines 49, 50: Expected error (tag 'method-str')
7-
Lines 53, 54: Expected error (tag 'method-bytes')
83
"""
94
output = """
5+
generics_scoping.py:15: error: Expression is of type "Literal[1]", not "int" [misc]
6+
generics_scoping.py:19: error: Expression is of type "Literal['a']", not "str" [misc]
107
generics_scoping.py:34: error: Argument 1 to "meth_2" of "MyClass" has incompatible type "str"; expected "int" [arg-type]
8+
generics_scoping.py:49: error: Expression is of type "Literal['abc']", not "str" [misc]
9+
generics_scoping.py:53: error: Expression is of type "Literal[b'abc']", not "bytes" [misc]
1110
generics_scoping.py:61: error: Type variable "generics_scoping.S" is unbound [misc]
1211
generics_scoping.py:61: note: (Hint: Use "Generic[S]" or "Protocol[S]" base class to bind "S" inside a class)
1312
generics_scoping.py:61: note: (Hint: Use "S" in function signature to bind "S" inside a function)

0 commit comments

Comments
 (0)