@@ -2312,18 +2312,18 @@ def good2(*args: str) -> int: ...
23122312# These are special-cased for *args: Any (as opposite to *args: object)
23132313def ok1(a: str, b: int, /) -> None: ...
23142314def ok2(c: bytes, *args: int) -> str: ...
2315+ def ok3(**kwargs: None) -> None: ...
23152316
23162317def bad1(*, d: str) -> int: ...
2317- def bad2(**kwargs: None) -> None: ...
23182318
23192319higher_order(good1)
23202320higher_order(good2)
23212321
23222322higher_order(ok1)
23232323higher_order(ok2)
2324+ higher_order(ok3)
23242325
23252326higher_order(bad1) # E: Argument 1 to "higher_order" has incompatible type "Callable[[NamedArg(str, 'd')], int]"; expected "Callable[[VarArg(Any)], Any]"
2326- higher_order(bad2) # E: Argument 1 to "higher_order" has incompatible type "Callable[[KwArg(None)], None]"; expected "Callable[[VarArg(Any)], Any]"
23272327[builtins fixtures/tuple.pyi]
23282328
23292329[case testAliasToCallableWithUnpack2]
@@ -2381,11 +2381,11 @@ def func(x: Array[Unpack[Ts]], *args: Unpack[Ts]) -> Tuple[Unpack[Ts]]:
23812381 ...
23822382
23832383def a2(x: Array[int, str]) -> None:
2384- reveal_type(func(x, 2, "Hello")) # N: Revealed type is "Tuple[builtins.int, builtins.str ]"
2385- reveal_type(func(x, 2)) # E: Cannot infer type argument 1 of "func " \
2386- # N: Revealed type is "builtins.tuple[Any, ... ]"
2387- reveal_type(func(x, 2, "Hello", True)) # E: Cannot infer type argument 1 of "func " \
2388- # N: Revealed type is "builtins.tuple[Any, ... ]"
2384+ reveal_type(func(x, 2, "Hello")) # N: Revealed type is "Tuple[Literal[2]?, Literal['Hello']? ]"
2385+ reveal_type(func(x, 2)) # N: Revealed type is "Tuple[Literal[2]?] " \
2386+ # E: Argument 1 to "func" has incompatible type "Array[int, str]"; expected "Array[int ]"
2387+ reveal_type(func(x, 2, "Hello", True)) # N: Revealed type is "Tuple[Literal[2]?, Literal['Hello']?, Literal[True]?] " \
2388+ # E: Argument 1 to "func" has incompatible type "Array[int, str]"; expected "Array[int, str, bool ]"
23892389[builtins fixtures/tuple.pyi]
23902390
23912391[case testTypeVarTupleTypeApplicationOverload]
@@ -2628,3 +2628,37 @@ def fn(f: Callable[[*tuple[T]], int]) -> Callable[[*tuple[T]], int]: ...
26282628def test(*args: Unpack[tuple[T]]) -> int: ...
26292629reveal_type(fn(test)) # N: Revealed type is "def [T] (T`1) -> builtins.int"
26302630[builtins fixtures/tuple.pyi]
2631+
2632+ [case testKwargWithTypeVarTupleInference]
2633+ # https://github.com/python/mypy/issues/16522
2634+ from typing import Generic, TypeVar, Protocol
2635+ from typing_extensions import TypeVarTuple, Unpack
2636+
2637+ PosArgT = TypeVarTuple("PosArgT")
2638+ StatusT = TypeVar("StatusT")
2639+ StatusT_co = TypeVar("StatusT_co", covariant=True)
2640+ StatusT_contra = TypeVar("StatusT_contra", contravariant=True)
2641+
2642+ class TaskStatus(Generic[StatusT_contra]):
2643+ def started(self, value: StatusT_contra) -> None: ...
2644+
2645+ class NurseryStartFunc(Protocol[Unpack[PosArgT], StatusT_co]):
2646+ def __call__(
2647+ self,
2648+ *args: Unpack[PosArgT],
2649+ task_status: TaskStatus[StatusT_co],
2650+ ) -> object: ...
2651+
2652+ def nursery_start(
2653+ async_fn: NurseryStartFunc[Unpack[PosArgT], StatusT],
2654+ *args: Unpack[PosArgT],
2655+ ) -> StatusT: ...
2656+
2657+ def task(a: int, b: str, *, task_status: TaskStatus[str]) -> None: ...
2658+
2659+ def test() -> None:
2660+ reveal_type(nursery_start(task, "a", 2)) # N: Revealed type is "builtins.str" \
2661+ # E: Argument 1 to "nursery_start" has incompatible type "Callable[[int, str, NamedArg(TaskStatus[str], 'task_status')], None]"; expected "NurseryStartFunc[str, int, str]" \
2662+ # N: "NurseryStartFunc[str, int, str].__call__" has type "Callable[[str, int, NamedArg(TaskStatus[str], 'task_status')], object]"
2663+ reveal_type(nursery_start(task, 1, "b")) # N: Revealed type is "builtins.str"
2664+ [builtins fixtures/tuple.pyi]
0 commit comments