Skip to content

Commit d69a129

Browse files
committed
fix crash in split_for_callable when passing values to variadic generics
1 parent 0cc21d9 commit d69a129

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

mypy/checkexpr.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4966,7 +4966,9 @@ class C(Generic[T, Unpack[Ts]]): ...
49664966
if not vars or not any(isinstance(v, TypeVarTupleType) for v in vars):
49674967
return list(args)
49684968
# TODO: in future we may want to support type application to variadic functions.
4969-
assert t.is_type_obj()
4969+
if not t.is_type_obj():
4970+
self.chk.fail(f"Invalid type argument: type expected, for {args[0]!r}", ctx)
4971+
return [AnyType(TypeOfAny.from_error)] * len(vars)
49704972
info = t.type_object()
49714973
# We reuse the logic from semanal phase to reduce code duplication.
49724974
fake = Instance(info, args, line=ctx.line, column=ctx.column)

test-data/unit/check-typevar-tuple.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,3 +2754,20 @@ class X(Generic[Unpack[Ts]]):
27542754
def c(t: X[Concatenate[int, ...]]) -> None: # E: Cannot use "[int, VarArg(Any), KwArg(Any)]" for TypeVarTuple, only for ParamSpec
27552755
reveal_type(t) # N: Revealed type is "__main__.X[Unpack[builtins.tuple[Any, ...]]]"
27562756
[builtins fixtures/tuple.pyi]
2757+
2758+
[case testTypeVarTupleLiteralValueAsTypeArgument]
2759+
# flags: --python-version 3.12
2760+
from typing import TypeVarTuple, Generic, Unpack
2761+
2762+
Ts = TypeVarTuple('Ts')
2763+
2764+
def fn[*T]() -> None:
2765+
pass
2766+
2767+
class C(Generic[*Ts]):
2768+
pass
2769+
2770+
x = C[1, 2, 3]() # E: Invalid type: try using Literal[1] instead? \
2771+
# E: Invalid type: try using Literal[2] instead? \
2772+
# E: Invalid type: try using Literal[3] instead?
2773+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)