From d61944d2652d94ef7df7535e287e4f6fc849a2a7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 9 Apr 2024 05:21:08 -0400 Subject: [PATCH] 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 --- conformance/results/mypy/tuples_unpacked.toml | 10 ++--- conformance/results/pyre/tuples_unpacked.toml | 38 ++++++++++--------- .../results/pyright/tuples_unpacked.toml | 14 +++---- .../results/pytype/tuples_unpacked.toml | 38 +++++++++++-------- conformance/tests/tuples_unpacked.py | 7 ++-- 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/conformance/results/mypy/tuples_unpacked.toml b/conformance/results/mypy/tuples_unpacked.toml index e2310b30d..ad33667a3 100644 --- a/conformance/results/mypy/tuples_unpacked.toml +++ b/conformance/results/mypy/tuples_unpacked.toml @@ -4,14 +4,12 @@ notes = """ """ output = """ tuples_unpacked.py: error: More than one Unpack in a type is not allowed [misc] -tuples_unpacked.py:58: error: More than one Unpack in a type is not allowed [misc] +tuples_unpacked.py:59: error: More than one Unpack in a type is not allowed [misc] """ conformance_automated = "Fail" errors_diff = """ -Line 31: Expected 1 errors -Line 32: Expected 1 errors -Line 39: Expected 1 errors Line 40: Expected 1 errors -Line 50: Expected 1 errors -Line 60: Expected 1 errors +Line 41: Expected 1 errors +Line 51: Expected 1 errors +Line 61: Expected 1 errors """ diff --git a/conformance/results/pyre/tuples_unpacked.toml b/conformance/results/pyre/tuples_unpacked.toml index 8dddd3c36..52ce6edc5 100644 --- a/conformance/results/pyre/tuples_unpacked.toml +++ b/conformance/results/pyre/tuples_unpacked.toml @@ -16,30 +16,34 @@ tuples_unpacked.py:25:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool 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]`. -tuples_unpacked.py:31:6 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type. -tuples_unpacked.py:32:6 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type. -tuples_unpacked.py:37:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type. -tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type. -tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *tuple[(int, ...)])]` is not a valid type. -tuples_unpacked.py:40:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])], *tuple[(int, ...)])]` is not a valid type. -tuples_unpacked.py:48:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type. -tuples_unpacked.py:49:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type. -tuples_unpacked.py:50:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *$local_tuples_unpacked$Ts)]` is not a valid type. -tuples_unpacked.py:56:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type. +tuples_unpacked.py:31:4 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type. +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]]`. +tuples_unpacked.py:33:4 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type. +tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type. +tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type. +tuples_unpacked.py:40:4 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *tuple[(int, ...)])]` is not a valid type. +tuples_unpacked.py:41:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])], *tuple[(int, ...)])]` is not a valid type. +tuples_unpacked.py:49:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type. +tuples_unpacked.py:50:8 Invalid type [31]: Expression `tuple[(*tuple[str], *$local_tuples_unpacked$Ts)]` is not a valid type. +tuples_unpacked.py:51:8 Invalid type [31]: Expression `tuple[(*tuple[(str, ...)], *$local_tuples_unpacked$Ts)]` is not a valid type. +tuples_unpacked.py:57:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type. """ conformance_automated = "Fail" errors_diff = """ -Line 58: Expected 1 errors -Line 60: Expected 1 errors +Line 59: Expected 1 errors +Line 61: Expected 1 errors Line 16: Unexpected errors ['tuples_unpacked.py:16:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, bool)], str)]` is not a valid type.'] 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]]`.'] 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]]`.'] 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]]`.'] Line 25: Unexpected errors ['tuples_unpacked.py:25:13 Invalid type [31]: Expression `tuple[(int, *tuple[(bool, ...)], str)]` is not a valid type.'] 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]`.'] -Line 37: Unexpected errors ['tuples_unpacked.py:37:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.'] -Line 38: Unexpected errors ['tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.'] -Line 48: Unexpected errors ['tuples_unpacked.py:48:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.'] -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.'] -Line 56: Unexpected errors ['tuples_unpacked.py:56:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.'] +Line 31: Unexpected errors ['tuples_unpacked.py:31:4 Invalid type [31]: Expression `tuple[(*tuple[int], *tuple[int])]` is not a valid type.'] +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]]`.'] +Line 33: Unexpected errors ['tuples_unpacked.py:33:4 Invalid type [31]: Expression `tuple[(*tuple[(int, ...)], *tuple[int])]` is not a valid type.'] +Line 38: Unexpected errors ['tuples_unpacked.py:38:4 Invalid type [31]: Expression `tuple[(*tuple[str], *tuple[str])]` is not a valid type.'] +Line 39: Unexpected errors ['tuples_unpacked.py:39:4 Invalid type [31]: Expression `tuple[(*tuple[(str, *tuple[(str, ...)])])]` is not a valid type.'] +Line 49: Unexpected errors ['tuples_unpacked.py:49:13 Invalid type [31]: Expression `tuple[(*$local_tuples_unpacked$Ts)]` is not a valid type.'] +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.'] +Line 57: Unexpected errors ['tuples_unpacked.py:57:5 Undefined or invalid type [11]: Annotation `Unpack` is not defined as a type.'] """ diff --git a/conformance/results/pyright/tuples_unpacked.toml b/conformance/results/pyright/tuples_unpacked.toml index 3c2f83887..71786b74a 100644 --- a/conformance/results/pyright/tuples_unpacked.toml +++ b/conformance/results/pyright/tuples_unpacked.toml @@ -1,13 +1,11 @@ conformant = "Pass" output = """ -tuples_unpacked.py:39:30 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple -tuples_unpacked.py:40:43 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple -tuples_unpacked.py:50:34 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple -tuples_unpacked.py:58:37 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple -tuples_unpacked.py:60:50 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple +tuples_unpacked.py:40:30 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple +tuples_unpacked.py:41:43 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple +tuples_unpacked.py:51:34 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple +tuples_unpacked.py:59:37 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple +tuples_unpacked.py:61:50 - error: Type argument list can have at most one unpacked TypeVarTuple or tuple """ -conformance_automated = "Fail" +conformance_automated = "Pass" errors_diff = """ -Line 31: Expected 1 errors -Line 32: Expected 1 errors """ diff --git a/conformance/results/pytype/tuples_unpacked.toml b/conformance/results/pytype/tuples_unpacked.toml index 9badad80c..ff0e3854f 100644 --- a/conformance/results/pytype/tuples_unpacked.toml +++ b/conformance/results/pytype/tuples_unpacked.toml @@ -12,26 +12,29 @@ File "tuples_unpacked.py", line 18, in func1: Invalid type annotation '' [invalid-annotation] File "tuples_unpacked.py", line 25, in : Invalid type annotation '' [invalid-annotation] File "tuples_unpacked.py", line 26, in func2: Invalid type annotation '' [invalid-annotation] +File "tuples_unpacked.py", line 31, in : Type annotation for u1 does not match type of assignment [annotation-type-mismatch] +File "tuples_unpacked.py", line 31, in : Invalid type annotation 'tuple[*tuple[int], *tuple[int]]' [invalid-annotation] File "tuples_unpacked.py", line 31, in : Invalid type annotation '' [invalid-annotation] File "tuples_unpacked.py", line 31, in : Function list.extend was called with the wrong arguments [wrong-arg-types] -File "tuples_unpacked.py", line 32, in : Invalid type annotation '' [invalid-annotation] -File "tuples_unpacked.py", line 32, in : Function list.extend was called with the wrong arguments [wrong-arg-types] -File "tuples_unpacked.py", line 37, in : Invalid type annotation '' [invalid-annotation] -File "tuples_unpacked.py", line 37, in : Function list.extend was called with the wrong arguments [wrong-arg-types] +File "tuples_unpacked.py", line 32, in : Tuple[Any] [assert-type] +File "tuples_unpacked.py", line 33, in : Invalid type annotation '' [invalid-annotation] +File "tuples_unpacked.py", line 33, in : Function list.extend was called with the wrong arguments [wrong-arg-types] File "tuples_unpacked.py", line 38, in : Invalid type annotation '' [invalid-annotation] +File "tuples_unpacked.py", line 38, in : Function list.extend was called with the wrong arguments [wrong-arg-types] File "tuples_unpacked.py", line 39, in : Invalid type annotation '' [invalid-annotation] -File "tuples_unpacked.py", line 39, in : Function list.extend was called with the wrong arguments [wrong-arg-types] File "tuples_unpacked.py", line 40, in : Invalid type annotation '' [invalid-annotation] File "tuples_unpacked.py", line 40, in : Function list.extend was called with the wrong arguments [wrong-arg-types] -File "tuples_unpacked.py", line 45, in : Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count] -File "tuples_unpacked.py", line 48, in : Invalid type annotation '' [invalid-annotation] -File "tuples_unpacked.py", line 49, in func3: Invalid type annotation 'tuple[*tuple[str], *Ts]' [invalid-annotation] -File "tuples_unpacked.py", line 50, in func3: Invalid type annotation 'tuple[*tuple[str, ...], *Ts]' [invalid-annotation] +File "tuples_unpacked.py", line 41, in : Invalid type annotation '' [invalid-annotation] +File "tuples_unpacked.py", line 41, in : Function list.extend was called with the wrong arguments [wrong-arg-types] +File "tuples_unpacked.py", line 46, in : Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count] +File "tuples_unpacked.py", line 49, in : Invalid type annotation '' [invalid-annotation] +File "tuples_unpacked.py", line 50, in func3: Invalid type annotation 'tuple[*tuple[str], *Ts]' [invalid-annotation] +File "tuples_unpacked.py", line 51, in func3: Invalid type annotation 'tuple[*tuple[str, ...], *Ts]' [invalid-annotation] """ conformance_automated = "Fail" errors_diff = """ -Line 58: Expected 1 errors -Line 60: Expected 1 errors +Line 59: Expected 1 errors +Line 61: Expected 1 errors Line 13: Unexpected errors ['File "tuples_unpacked.py", line 13, in : typing.Unpack not supported yet [not-supported-yet]', 'File "tuples_unpacked.py", line 13, in : typing.TypeVarTuple not supported yet [not-supported-yet]'] Line 16: Unexpected errors ['File "tuples_unpacked.py", line 16, in : Invalid type annotation \\'\\' [invalid-annotation]'] Line 17: Unexpected errors ['File "tuples_unpacked.py", line 17, in func1: Tuple[Any] [assert-type]'] @@ -39,9 +42,12 @@ Line 18: Unexpected errors ['File "tuples_unpacked.py", line 18, in func1: Inval Line 19: Unexpected errors ['File "tuples_unpacked.py", line 19, in func1: Invalid type annotation \\'\\' [invalid-annotation]'] Line 25: Unexpected errors ['File "tuples_unpacked.py", line 25, in : Invalid type annotation \\'\\' [invalid-annotation]'] Line 26: Unexpected errors ['File "tuples_unpacked.py", line 26, in func2: Invalid type annotation \\'\\' [invalid-annotation]'] -Line 37: Unexpected errors ['File "tuples_unpacked.py", line 37, in : Invalid type annotation \\'\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 37, in : Function list.extend was called with the wrong arguments [wrong-arg-types]'] -Line 38: Unexpected errors ['File "tuples_unpacked.py", line 38, in : Invalid type annotation \\'\\' [invalid-annotation]'] -Line 45: Unexpected errors ['File "tuples_unpacked.py", line 45, in : Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]'] -Line 48: Unexpected errors ['File "tuples_unpacked.py", line 48, in : Invalid type annotation \\'\\' [invalid-annotation]'] -Line 49: Unexpected errors ['File "tuples_unpacked.py", line 49, in func3: Invalid type annotation \\'tuple[*tuple[str], *Ts]\\' [invalid-annotation]'] +Line 31: Unexpected errors ['File "tuples_unpacked.py", line 31, in : Type annotation for u1 does not match type of assignment [annotation-type-mismatch]', 'File "tuples_unpacked.py", line 31, in : Invalid type annotation \\'tuple[*tuple[int], *tuple[int]]\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 31, in : Invalid type annotation \\'\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 31, in : Function list.extend was called with the wrong arguments [wrong-arg-types]'] +Line 32: Unexpected errors ['File "tuples_unpacked.py", line 32, in : Tuple[Any] [assert-type]'] +Line 33: Unexpected errors ['File "tuples_unpacked.py", line 33, in : Invalid type annotation \\'\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 33, in : Function list.extend was called with the wrong arguments [wrong-arg-types]'] +Line 38: Unexpected errors ['File "tuples_unpacked.py", line 38, in : Invalid type annotation \\'\\' [invalid-annotation]', 'File "tuples_unpacked.py", line 38, in : Function list.extend was called with the wrong arguments [wrong-arg-types]'] +Line 39: Unexpected errors ['File "tuples_unpacked.py", line 39, in : Invalid type annotation \\'\\' [invalid-annotation]'] +Line 46: Unexpected errors ['File "tuples_unpacked.py", line 46, in : Function TypeVarTuple.__init__ expects 1 arg(s), got 2 [wrong-arg-count]'] +Line 49: Unexpected errors ['File "tuples_unpacked.py", line 49, in : Invalid type annotation \\'\\' [invalid-annotation]'] +Line 50: Unexpected errors ['File "tuples_unpacked.py", line 50, in func3: Invalid type annotation \\'tuple[*tuple[str], *Ts]\\' [invalid-annotation]'] """ diff --git a/conformance/tests/tuples_unpacked.py b/conformance/tests/tuples_unpacked.py index dc7f6cd4c..ca58af7a7 100644 --- a/conformance/tests/tuples_unpacked.py +++ b/conformance/tests/tuples_unpacked.py @@ -26,10 +26,11 @@ def func2(x: tuple[int, *tuple[bool, ...], str]): assert_type(x, tuple[int, *tuple[bool, ...], str]) -# > As with TypeVarTuples, only one unpacking may appear in a tuple: +# > For example, tuple[int, *tuple[str]] is equivalent to tuple[int, str]. -bad1: tuple[*tuple[int], *tuple[int]] # E -bad2: tuple[*tuple[int, ...], *tuple[int]] # E +u1: tuple[*tuple[int], *tuple[int]] = (int(1), int(1)) # OK +assert_type(u1, tuple[int, int]) +u2: tuple[*tuple[int, ...], *tuple[int]] # OK # > Only one unbounded tuple can be used within another tuple: