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
2 changes: 1 addition & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def visit_instance(self, t: Instance) -> Type:
# See: https://github.com/python/mypy/issues/16649
return t.copy_modified(args=args)

if t.type.fullname == "builtins.tuple":
if t.type.fullname == "builtins.tuple" and len(args) > 0:
# Normalize Tuple[*Tuple[X, ...], ...] -> Tuple[X, ...]
arg = args[0]
if isinstance(arg, UnpackType):
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2237,3 +2237,16 @@ class D[*Ts](Generic[Unpack[Us]]): # E: Generic[...] base class is redundant \
# E: Can only use one type var tuple in a class def
pass
[builtins fixtures/tuple.pyi]

[case testUnpackEmptyTupleInTypeAliasNoCrash]
# https://github.com/python/mypy/issues/20913
from typing import Unpack

class C[*Ts]:
pass

type T[T, *Ts] = C[*Ts]

x: T[bool, Unpack[tuple[()]]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a reveal type to make sure the type is being preserved?

[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]