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: 2 additions & 0 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def tuple_fallback(typ: TupleType) -> Instance:
and unpacked_type.type.fullname == "builtins.tuple"
):
items.append(unpacked_type.args[0])
elif isinstance(unpacked_type, TupleType):
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIRC the idea was that it should never be true when we call tuple_fallback - we have several places where things like tuple[*tuple[X,Y]] are normalized to a plain tuple, and the original intent was to get rid of such constructs as early as possible. This is fine as a quickfix, but I'm afraid that this will manifest again when such nested tuple is used elsewhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not entirely sure about that but isn't the function already doing the flatting? E.g. just the line above flattens builtins.tuple Instances.

Copy link
Collaborator

Choose a reason for hiding this comment

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

builtins.tuple is already normalized: you can't rewrite e.g. tuple[str, *tuple[int, ...]] as a single tuple[...] construct. This is only about expanding unpacks of fixed-size TupleType types (which is always possible), see flatten_nested_tuples

items.extend(unpacked_type.items)
else:
raise NotImplementedError
else:
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-typevar-defaults.test
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ T4 = TypeVar("T4", int, str, default=int)
T5 = TypeVar("T5", default=S0)
T6 = TypeVar("T6", bound=float, default=S1)
T7 = TypeVar("T7", bound=List[Any], default=List[S0])
T8 = TypeVar("T8", default=Tuple[int, Unpack[Tuple[int, str]]])

P1 = ParamSpec("P1", default=[])
P2 = ParamSpec("P2", default=...)
Expand Down