2Tests the use of TypeVarTuple within a Callable.
5# Specification: https://typing.readthedocs.io/en/latest/spec/generics.html#type-variable-tuples-with-callable
7# > Type variable tuples can also be used in the arguments section of a Callable.
10from typing import Callable, TypeVar, TypeVarTuple, assert_type
12Ts = TypeVarTuple("Ts")
17 def __init__(self, target: Callable[[*Ts], None], args: tuple[*Ts]) -> None:
21def func1(arg1: int, arg2: str) -> None:
25Process(target=func1, args=(0, "")) # OK
26Process(target=func1, args=("", 0)) # E
Expected a ty diagnostic for this line
29def func2(f: Callable[[int, *Ts, T], tuple[T, *Ts]]) -> tuple[*Ts, T]:
30 raise NotImplementedError
33def callback1(a: int, b: str, c: int, d: complex) -> tuple[complex, str, int]:
34 raise NotImplementedError
37def callback2(a: int, d: str) -> tuple[str]:
38 raise NotImplementedError
41assert_type(func2(callback1), tuple[str, int, complex])
Unexpected error
[type-assertion-failure] Type `tuple[str, int, int | float | complex]` does not match asserted type `tuple[@Todo(TypeVarTuple), ...]`
42assert_type(func2(callback2), tuple[str])
Unexpected error
[type-assertion-failure] Type `tuple[str]` does not match asserted type `tuple[@Todo(TypeVarTuple), ...]`
45def func3(*args: * tuple[int, *Ts, T]) -> tuple[T, *Ts]:
46 raise NotImplementedError
49assert_type(func3(1, "", 3j, 3.4), tuple[float, str, complex])
Unexpected error
[type-assertion-failure] Type `tuple[int | float, str, int | float | complex]` does not match asserted type `tuple[@Todo(TypeVarTuple), ...]`