Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Dec 7, 2023
1 parent 88fec70 commit e4d02a4
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,24 @@ def interpolate_args_for_unpack(self, t: CallableType, var_arg: UnpackType) -> l
suffix = self.expand_types(t.arg_types[star_index + 1 :])

var_arg_type = get_proper_type(var_arg.type)
if isinstance(var_arg_type, TupleType):
# We have something like Unpack[Tuple[Unpack[Ts], X1, X2]]
expanded_tuple = var_arg_type.accept(self)
assert isinstance(expanded_tuple, ProperType) and isinstance(expanded_tuple, TupleType)
expanded_items = expanded_tuple.items
fallback = var_arg_type.partial_fallback
elif isinstance(var_arg_type, Instance):
# We have something like Unpack[Tuple[Any, ...]]
expanded_items = list(var_arg_type.args)
fallback = var_arg_type
if isinstance(var_arg_type, Instance):
# we have something like Unpack[Tuple[Any, ...]]
new_unpack = var_arg
else:
# We have plain Unpack[Ts]
assert isinstance(var_arg_type, TypeVarTupleType), type(var_arg_type)
fallback = var_arg_type.tuple_fallback
expanded_items = self.expand_unpack(var_arg)
new_unpack = UnpackType(TupleType(expanded_items, fallback))
if isinstance(var_arg_type, TupleType):
# We have something like Unpack[Tuple[Unpack[Ts], X1, X2]]
expanded_tuple = var_arg_type.accept(self)
assert isinstance(expanded_tuple, ProperType) and isinstance(
expanded_tuple, TupleType
)
expanded_items = expanded_tuple.items
fallback = var_arg_type.partial_fallback
else:
# We have plain Unpack[Ts]
assert isinstance(var_arg_type, TypeVarTupleType), type(var_arg_type)
fallback = var_arg_type.tuple_fallback
expanded_items = self.expand_unpack(var_arg)
new_unpack = UnpackType(TupleType(expanded_items, fallback))
return prefix + [new_unpack] + suffix

def visit_callable_type(self, t: CallableType) -> CallableType:
Expand Down

0 comments on commit e4d02a4

Please sign in to comment.