diff --git a/mypy/test/testpythoneval.py b/mypy/test/testpythoneval.py index 62ba54591d9d..1fd342452102 100644 --- a/mypy/test/testpythoneval.py +++ b/mypy/test/testpythoneval.py @@ -61,7 +61,17 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None m = re.search("# flags: (.*)$", "\n".join(testcase.input), re.MULTILINE) if m: - mypy_cmdline.extend(m.group(1).split()) + additional_flags = m.group(1).split() + for flag in additional_flags: + if flag.startswith("--python-version="): + targetted_python_version = flag.split("=")[1] + targetted_major, targetted_minor = targetted_python_version.split(".") + if (int(targetted_major), int(targetted_minor)) > ( + sys.version_info.major, + sys.version_info.minor, + ): + return + mypy_cmdline.extend(additional_flags) # Write the program to a file. program = "_" + testcase.name + ".py" diff --git a/mypy/typeanal.py b/mypy/typeanal.py index d09fa5e339d1..5b51d07dfde4 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -1298,7 +1298,7 @@ def analyze_callable_args( # Potentially a unpack. sym = self.lookup_qualified(arg.name, arg) if sym is not None: - if sym.fullname == "typing_extensions.Unpack": + if sym.fullname in ("typing_extensions.Unpack", "typing.Unpack"): if found_unpack: self.fail("Callables can only have a single unpack", arg) found_unpack = True diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 034c2190dd5e..760a761705f4 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1986,3 +1986,28 @@ def good9(foo1: Foo[Concatenate[int, P]], foo2: Foo[[int, str, bytes]], *args: P [out] _testStrictEqualitywithParamSpec.py:11: error: Non-overlapping equality check (left operand type: "Foo[[int]]", right operand type: "Bar[[int]]") + +[case testTypeVarTuple] +# flags: --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack --python-version=3.11 +from typing import Any, Callable, Unpack, TypeVarTuple + +Ts = TypeVarTuple("Ts") + +def foo(callback: Callable[[], Any]) -> None: + call(callback) + +def call(callback: Callable[[Unpack[Ts]], Any], *args: Unpack[Ts]) -> Any: + ... + +[case testTypeVarTupleTypingExtensions] +# flags: --enable-incomplete-feature=TypeVarTuple --enable-incomplete-feature=Unpack +from typing_extensions import Unpack, TypeVarTuple +from typing import Any, Callable + +Ts = TypeVarTuple("Ts") + +def foo(callback: Callable[[], Any]) -> None: + call(callback) + +def call(callback: Callable[[Unpack[Ts]], Any], *args: Unpack[Ts]) -> Any: + ...