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
9 changes: 6 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -4963,10 +4963,13 @@ class C(Generic[T, Unpack[Ts]]): ...
)
return [AnyType(TypeOfAny.from_error)] * len(vars)

if not vars or not any(isinstance(v, TypeVarTupleType) for v in vars):
return list(args)
# TODO: in future we may want to support type application to variadic functions.
assert t.is_type_obj()
if (
not vars
or not any(isinstance(v, TypeVarTupleType) for v in vars)
or not t.is_type_obj()
):
return list(args)
info = t.type_object()
# We reuse the logic from semanal phase to reduce code duplication.
fake = Instance(info, args, line=ctx.line, column=ctx.column)
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -2754,3 +2754,15 @@ class X(Generic[Unpack[Ts]]):
def c(t: X[Concatenate[int, ...]]) -> None: # E: Cannot use "[int, VarArg(Any), KwArg(Any)]" for TypeVarTuple, only for ParamSpec
reveal_type(t) # N: Revealed type is "__main__.X[Unpack[builtins.tuple[Any, ...]]]"
[builtins fixtures/tuple.pyi]

[case testTypeVarTupleLiteralValueAsTypeArgument]
from typing import TypeVarTuple, Unpack, Callable, TypeVar

Ts = TypeVarTuple('Ts')
T = TypeVar('T')

def func(d: Callable[[Unpack[Ts]], T]) -> T: ...

y = func[1, int] # E: Type application is only supported for generic classes \
# E: Invalid type: try using Literal[1] instead?
[builtins fixtures/tuple.pyi]