Skip to content
Merged
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
3 changes: 3 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,9 @@ def analyze_unbound_tvar(self, t: Type) -> tuple[str, TypeVarLikeExpr] | None:
if isinstance(t, UnboundType):
sym = self.lookup_qualified(t.name, t)
if sym and sym.fullname in UNPACK_TYPE_NAMES:
if not t.args:
# Unpack used without arguments, e.g. `Protocol[Unpack]`
return None
inner_t = t.args[0]
if isinstance(inner_t, UnboundType):
return self.analyze_unbound_tvar_impl(inner_t, is_unpacked=True)
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -2765,3 +2765,11 @@ 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]

[case testTypeVarTupleUnpackWithoutArgsInProtocol]
# https://github.com/python/mypy/issues/21467
from typing import Protocol, Unpack

class C(Protocol[Unpack]): # E: Free type variable expected in Protocol[...]
pass
[builtins fixtures/tuple.pyi]
Loading