Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mypy/types_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-generics.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Loading