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
17 changes: 15 additions & 2 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,22 @@ def expand_unpack(self, t: UnpackType) -> list[Type]:
raise RuntimeError(f"Invalid type replacement to expand: {repl}")

def visit_parameters(self, t: Parameters) -> Type:
return t.copy_modified(arg_types=self.expand_types(t.arg_types))
# This mimics the logic in visit_callable_type().
var_arg = t.var_arg()
needs_normalization = False

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we also look at self.normalize_callables -- is it relevant here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, I think we are fine (even for callables we really need to keep original shape only for top-level callables).

if var_arg is not None and isinstance(var_arg.typ, UnpackType):
needs_normalization = True
arg_types = self.interpolate_args_for_unpack(t, var_arg.typ)
else:
arg_types = self.expand_types(t.arg_types)
expanded = t.copy_modified(arg_types=arg_types)
if needs_normalization:
expanded = expanded.with_normalized_var_args()
return expanded

def interpolate_args_for_unpack(self, t: CallableType, var_arg: UnpackType) -> list[Type]:
def interpolate_args_for_unpack(
self, t: CallableType | Parameters, var_arg: UnpackType
) -> list[Type]:
star_index = t.arg_kinds.index(ARG_STAR)
prefix = self.expand_types(t.arg_types[:star_index])
suffix = self.expand_types(t.arg_types[star_index + 1 :])
Expand Down
Loading
Loading