diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 9990caaeb7a1..9408d70e50f7 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -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) diff --git a/test-data/unit/check-typevar-tuple.test b/test-data/unit/check-typevar-tuple.test index f6d9de8b0c1a..0b7f8fe06749 100644 --- a/test-data/unit/check-typevar-tuple.test +++ b/test-data/unit/check-typevar-tuple.test @@ -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]