Skip to content

Commit d61944d

Browse files
Conformance tests: Fix tuples_unpacked.py (#1703)
I can't find the quoted phrase in the spec and I don't see a reason why this should error. Part of #1692
1 parent 3998da0 commit d61944d

File tree

5 files changed

+57
-50
lines changed

5 files changed

+57
-50
lines changed

conformance/results/mypy/tuples_unpacked.toml

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ notes = """
44
"""
55
output = """
66
tuples_unpacked.py: error: More than one Unpack in a type is not allowed [misc]
7-
tuples_unpacked.py:58: error: More than one Unpack in a type is not allowed [misc]
7+
tuples_unpacked.py:59: error: More than one Unpack in a type is not allowed [misc]
88
"""
99
conformance_automated = "Fail"
1010
errors_diff = """
11-
Line 31: Expected 1 errors
12-
Line 32: Expected 1 errors
13-
Line 39: Expected 1 errors
1411
Line 40: Expected 1 errors
15-
Line 50: Expected 1 errors
16-
Line 60: Expected 1 errors
12+
Line 41: Expected 1 errors
13+
Line 51: Expected 1 errors
14+
Line 61: Expected 1 errors
1715
"""

conformance/results/pyre/tuples_unpacked.toml

+21-17
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,34 @@ tuples_unpacked.py:25:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool
1616
tuples_unpacked.py:26:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[Type[int], *Tuple[typing.Any, ...], Type[str]]`.
1717
tuples_unpacked.py:26:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.
1818
tuples_unpacked.py:26:37 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[bool], typing.Any]`.
19-
tuples_unpacked.py:31:6 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type.
20-
tuples_unpacked.py:32:6 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type.
21-
tuples_unpacked.py:37:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.
22-
tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.
23-
tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *tuple[(int, ...)])]` is not a valid type.
24-
tuples_unpacked.py:40:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])], *tuple[(int, ...)])]` is not a valid type.
25-
tuples_unpacked.py:48:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.
26-
tuples_unpacked.py:49:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type.
27-
tuples_unpacked.py:50:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *$local_tuples_unpacked$Ts)]` is not a valid type.
28-
tuples_unpacked.py:56:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.
19+
tuples_unpacked.py:31:4 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type.
20+
tuples_unpacked.py:32:22 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], Type[int]]`.
21+
tuples_unpacked.py:33:4 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type.
22+
tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.
23+
tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.
24+
tuples_unpacked.py:40:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *tuple[(int, ...)])]` is not a valid type.
25+
tuples_unpacked.py:41:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])], *tuple[(int, ...)])]` is not a valid type.
26+
tuples_unpacked.py:49:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.
27+
tuples_unpacked.py:50:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type.
28+
tuples_unpacked.py:51:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *$local_tuples_unpacked$Ts)]` is not a valid type.
29+
tuples_unpacked.py:57:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.
2930
"""
3031
conformance_automated = "Fail"
3132
errors_diff = """
32-
Line 58: Expected 1 errors
33-
Line 60: Expected 1 errors
33+
Line 59: Expected 1 errors
34+
Line 61: Expected 1 errors
3435
Line 16: Unexpected errors ['tuples_unpacked.py:16:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, bool)], str)]` is not a valid type.']
3536
Line 17: Unexpected errors ['tuples_unpacked.py:17:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], Type[bool], Type[bool], Type[str]]`.']
3637
Line 18: Unexpected errors ['tuples_unpacked.py:18:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[*Tuple[typing.Any, ...], Type[bool], Type[str]]`.', 'tuples_unpacked.py:18:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.', 'tuples_unpacked.py:18:32 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], Type[bool]]`.']
3738
Line 19: Unexpected errors ['tuples_unpacked.py:19:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[Type[int], Type[bool], *Tuple[typing.Any, ...]]`.', 'tuples_unpacked.py:19:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.', 'tuples_unpacked.py:19:43 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[bool], Type[str]]`.']
3839
Line 25: Unexpected errors ['tuples_unpacked.py:25:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, ...)], str)]` is not a valid type.']
3940
Line 26: Unexpected errors ['tuples_unpacked.py:26:25 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `typing.Tuple[Type[int], *Tuple[typing.Any, ...], Type[str]]`.', 'tuples_unpacked.py:26:25 Unable to concatenate tuple [60]: Expected to unpack an iterable, but got `typing.Type[tuple[Variable[_T_co](covariant)]]`.', 'tuples_unpacked.py:26:37 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[bool], typing.Any]`.']
40-
Line 37: Unexpected errors ['tuples_unpacked.py:37:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.']
41-
Line 38: Unexpected errors ['tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.']
42-
Line 48: Unexpected errors ['tuples_unpacked.py:48:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.']
43-
Line 49: Unexpected errors ['tuples_unpacked.py:49:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type.']
44-
Line 56: Unexpected errors ['tuples_unpacked.py:56:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.']
41+
Line 31: Unexpected errors ['tuples_unpacked.py:31:4 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type.']
42+
Line 32: Unexpected errors ['tuples_unpacked.py:32:22 Incompatible parameter type [6]: In call `typing.GenericMeta.__getitem__`, for 1st positional argument, expected `Type[Variable[_T_co](covariant)]` but got `Tuple[Type[int], Type[int]]`.']
43+
Line 33: Unexpected errors ['tuples_unpacked.py:33:4 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type.']
44+
Line 38: Unexpected errors ['tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.']
45+
Line 39: Unexpected errors ['tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.']
46+
Line 49: Unexpected errors ['tuples_unpacked.py:49:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.']
47+
Line 50: Unexpected errors ['tuples_unpacked.py:50:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type.']
48+
Line 57: Unexpected errors ['tuples_unpacked.py:57:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.']
4549
"""
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
conformant = "Pass"
22
output = """
3-
tuples_unpacked.py:39:30 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
4-
tuples_unpacked.py:40:43 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
5-
tuples_unpacked.py:50:34 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
6-
tuples_unpacked.py:58:37 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
7-
tuples_unpacked.py:60:50 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
3+
tuples_unpacked.py:40:30 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
4+
tuples_unpacked.py:41:43 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
5+
tuples_unpacked.py:51:34 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
6+
tuples_unpacked.py:59:37 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
7+
tuples_unpacked.py:61:50 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple
88
"""
9-
conformance_automated = "Fail"
9+
conformance_automated = "Pass"
1010
errors_diff = """
11-
Line 31: Expected 1 errors
12-
Line 32: Expected 1 errors
1311
"""

conformance/results/pytype/tuples_unpacked.toml

+22-16
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,42 @@ File "tuples_unpacked.py", line 18, in func1: Invalid type annotation '<instance
1212
File "tuples_unpacked.py", line 19, in func1: Invalid type annotation '<instance of tuple>' [invalid-annotation]
1313
File "tuples_unpacked.py", line 25, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
1414
File "tuples_unpacked.py", line 26, in func2: Invalid type annotation '<instance of tuple>' [invalid-annotation]
15+
File "tuples_unpacked.py", line 31, in <module>: Type annotation for u1 does not match type of assignment [annotation-type-mismatch]
16+
File "tuples_unpacked.py", line 31, in <module>: Invalid type annotation 'tuple[*tuple[int], *tuple[int]]' [invalid-annotation]
1517
File "tuples_unpacked.py", line 31, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
1618
File "tuples_unpacked.py", line 31, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
17-
File "tuples_unpacked.py", line 32, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
18-
File "tuples_unpacked.py", line 32, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
19-
File "tuples_unpacked.py", line 37, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
20-
File "tuples_unpacked.py", line 37, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
19+
File "tuples_unpacked.py", line 32, in <module>: Tuple[Any] [assert-type]
20+
File "tuples_unpacked.py", line 33, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
21+
File "tuples_unpacked.py", line 33, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
2122
File "tuples_unpacked.py", line 38, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
23+
File "tuples_unpacked.py", line 38, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
2224
File "tuples_unpacked.py", line 39, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
23-
File "tuples_unpacked.py", line 39, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
2425
File "tuples_unpacked.py", line 40, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
2526
File "tuples_unpacked.py", line 40, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
26-
File "tuples_unpacked.py", line 45, in <module>: Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]
27-
File "tuples_unpacked.py", line 48, in <module>: Invalid type annotation '<instance of Tuple[nothing, ...]>' [invalid-annotation]
28-
File "tuples_unpacked.py", line 49, in func3: Invalid type annotation 'tuple[*tuple[str], *Ts]' [invalid-annotation]
29-
File "tuples_unpacked.py", line 50, in func3: Invalid type annotation 'tuple[*tuple[str, ...], *Ts]' [invalid-annotation]
27+
File "tuples_unpacked.py", line 41, in <module>: Invalid type annotation '<instance of tuple>' [invalid-annotation]
28+
File "tuples_unpacked.py", line 41, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]
29+
File "tuples_unpacked.py", line 46, in <module>: Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]
30+
File "tuples_unpacked.py", line 49, in <module>: Invalid type annotation '<instance of Tuple[nothing, ...]>' [invalid-annotation]
31+
File "tuples_unpacked.py", line 50, in func3: Invalid type annotation 'tuple[*tuple[str], *Ts]' [invalid-annotation]
32+
File "tuples_unpacked.py", line 51, in func3: Invalid type annotation 'tuple[*tuple[str, ...], *Ts]' [invalid-annotation]
3033
"""
3134
conformance_automated = "Fail"
3235
errors_diff = """
33-
Line 58: Expected 1 errors
34-
Line 60: Expected 1 errors
36+
Line 59: Expected 1 errors
37+
Line 61: Expected 1 errors
3538
Line 13: Unexpected errors ['File "tuples_unpacked.py", line 13, in <module>: typing.Unpack not supported yet [not-supported-yet]', 'File "tuples_unpacked.py", line 13, in <module>: typing.TypeVarTuple not supported yet [not-supported-yet]']
3639
Line 16: Unexpected errors ['File "tuples_unpacked.py", line 16, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
3740
Line 17: Unexpected errors ['File "tuples_unpacked.py", line 17, in func1: Tuple[Any] [assert-type]']
3841
Line 18: Unexpected errors ['File "tuples_unpacked.py", line 18, in func1: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
3942
Line 19: Unexpected errors ['File "tuples_unpacked.py", line 19, in func1: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
4043
Line 25: Unexpected errors ['File "tuples_unpacked.py", line 25, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
4144
Line 26: Unexpected errors ['File "tuples_unpacked.py", line 26, in func2: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
42-
Line 37: Unexpected errors ['File "tuples_unpacked.py", line 37, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 37, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]']
43-
Line 38: Unexpected errors ['File "tuples_unpacked.py", line 38, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
44-
Line 45: Unexpected errors ['File "tuples_unpacked.py", line 45, in <module>: Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]']
45-
Line 48: Unexpected errors ['File "tuples_unpacked.py", line 48, in <module>: Invalid type annotation \\'<instance of Tuple[nothing, ...]>\\' [invalid-annotation]']
46-
Line 49: Unexpected errors ['File "tuples_unpacked.py", line 49, in func3: Invalid type annotation \\'tuple[*tuple[str], *Ts]\\' [invalid-annotation]']
45+
Line 31: Unexpected errors ['File "tuples_unpacked.py", line 31, in <module>: Type annotation for u1 does not match type of assignment [annotation-type-mismatch]', 'File "tuples_unpacked.py", line 31, in <module>: Invalid type annotation \\'tuple[*tuple[int], *tuple[int]]\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 31, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 31, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]']
46+
Line 32: Unexpected errors ['File "tuples_unpacked.py", line 32, in <module>: Tuple[Any] [assert-type]']
47+
Line 33: Unexpected errors ['File "tuples_unpacked.py", line 33, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 33, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]']
48+
Line 38: Unexpected errors ['File "tuples_unpacked.py", line 38, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 38, in <module>: Function list.extend was called with the wrong arguments [wrong-arg-types]']
49+
Line 39: Unexpected errors ['File "tuples_unpacked.py", line 39, in <module>: Invalid type annotation \\'<instance of tuple>\\' [invalid-annotation]']
50+
Line 46: Unexpected errors ['File "tuples_unpacked.py", line 46, in <module>: Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]']
51+
Line 49: Unexpected errors ['File "tuples_unpacked.py", line 49, in <module>: Invalid type annotation \\'<instance of Tuple[nothing, ...]>\\' [invalid-annotation]']
52+
Line 50: Unexpected errors ['File "tuples_unpacked.py", line 50, in func3: Invalid type annotation \\'tuple[*tuple[str], *Ts]\\' [invalid-annotation]']
4753
"""

conformance/tests/tuples_unpacked.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ def func2(x: tuple[int, *tuple[bool, ...], str]):
2626
assert_type(x, tuple[int, *tuple[bool, ...], str])
2727

2828

29-
# > As with TypeVarTuples, only one unpacking may appear in a tuple:
29+
# > For example, tuple[int, *tuple[str]] is equivalent to tuple[int, str].
3030

31-
bad1: tuple[*tuple[int], *tuple[int]] # E
32-
bad2: tuple[*tuple[int, ...], *tuple[int]] # E
31+
u1: tuple[*tuple[int], *tuple[int]] = (int(1), int(1)) # OK
32+
assert_type(u1, tuple[int, int])
33+
u2: tuple[*tuple[int, ...], *tuple[int]] # OK
3334

3435

3536
# > Only one unbounded tuple can be used within another tuple:

0 commit comments

Comments
 (0)