diff --git a/mypy/types_utils.py b/mypy/types_utils.py index 160f6c0365d6..d9e6d7c35c17 100644 --- a/mypy/types_utils.py +++ b/mypy/types_utils.py @@ -154,6 +154,10 @@ def is_self_type_like(typ: Type, *, is_classmethod: bool) -> bool: def store_argument_type( defn: FuncItem, i: int, typ: CallableType, named_type: Callable[[str, list[Type]], Instance] ) -> None: + # Expanding an unpacked tuple can add synthetic positional arguments to + # the callable type without adding corresponding AST arguments. + if i >= len(defn.arguments): + return arg_type = typ.arg_types[i] if typ.arg_kinds[i] == ARG_STAR: if isinstance(arg_type, ParamSpecType): diff --git a/test-data/unit/check-generics.test b/test-data/unit/check-generics.test index b8f7a5699e19..4b056677abbc 100644 --- a/test-data/unit/check-generics.test +++ b/test-data/unit/check-generics.test @@ -3737,3 +3737,14 @@ def test(tp: type[T]) -> T: ... class C(Generic[T]): ... reveal_type(test(C)) # N: Revealed type is "__main__.C[Any]" + +[case testConstrainedTypeVarWithUnpackedArgs] +from typing import Callable, Tuple, TypeVar +from typing_extensions import Unpack + +T = TypeVar("T", str, bytes) + +def generic_fun(a: Callable[..., T], *args: Unpack[Tuple[int, float]]) -> None: ... + +generic_fun(lambda: "value", 1, 2.0) +[builtins fixtures/tuple.pyi]