|
26 | 26 | Type, |
27 | 27 | TypeAliasType, |
28 | 28 | TypedDictType, |
| 29 | + TypeOfAny, |
29 | 30 | TypeType, |
30 | 31 | TypeVarId, |
31 | 32 | TypeVarLikeType, |
@@ -312,24 +313,26 @@ def interpolate_args_for_unpack(self, t: CallableType, var_arg: UnpackType) -> l |
312 | 313 | suffix = self.expand_types(t.arg_types[star_index + 1 :]) |
313 | 314 |
|
314 | 315 | var_arg_type = get_proper_type(var_arg.type) |
| 316 | + new_unpack: Type |
315 | 317 | if isinstance(var_arg_type, Instance): |
316 | 318 | # we have something like Unpack[Tuple[Any, ...]] |
317 | 319 | new_unpack = var_arg |
318 | | - else: |
319 | | - if isinstance(var_arg_type, TupleType): |
320 | | - # We have something like Unpack[Tuple[Unpack[Ts], X1, X2]] |
321 | | - expanded_tuple = var_arg_type.accept(self) |
322 | | - assert isinstance(expanded_tuple, ProperType) and isinstance( |
323 | | - expanded_tuple, TupleType |
324 | | - ) |
325 | | - expanded_items = expanded_tuple.items |
326 | | - fallback = var_arg_type.partial_fallback |
327 | | - else: |
328 | | - # We have plain Unpack[Ts] |
329 | | - assert isinstance(var_arg_type, TypeVarTupleType), type(var_arg_type) |
330 | | - fallback = var_arg_type.tuple_fallback |
331 | | - expanded_items = self.expand_unpack(var_arg) |
| 320 | + elif isinstance(var_arg_type, TupleType): |
| 321 | + # We have something like Unpack[Tuple[Unpack[Ts], X1, X2]] |
| 322 | + expanded_tuple = var_arg_type.accept(self) |
| 323 | + assert isinstance(expanded_tuple, ProperType) and isinstance(expanded_tuple, TupleType) |
| 324 | + expanded_items = expanded_tuple.items |
| 325 | + fallback = var_arg_type.partial_fallback |
332 | 326 | new_unpack = UnpackType(TupleType(expanded_items, fallback)) |
| 327 | + elif isinstance(var_arg_type, TypeVarTupleType): |
| 328 | + # We have plain Unpack[Ts] |
| 329 | + fallback = var_arg_type.tuple_fallback |
| 330 | + expanded_items = self.expand_unpack(var_arg) |
| 331 | + new_unpack = UnpackType(TupleType(expanded_items, fallback)) |
| 332 | + else: |
| 333 | + # We have invalid type in Unpack. This can happen when expanding aliases |
| 334 | + # to Callable[[*Invalid], Ret] |
| 335 | + new_unpack = AnyType(TypeOfAny.from_error, line=var_arg.line, column=var_arg.column) |
333 | 336 | return prefix + [new_unpack] + suffix |
334 | 337 |
|
335 | 338 | def visit_callable_type(self, t: CallableType) -> CallableType: |
|
0 commit comments