(tup: TupleType, target: int)
| 744 | |
| 745 | |
| 746 | def expand_tuple_if_possible(tup: TupleType, target: int) -> TupleType: |
| 747 | if len(tup.items) > target + 1: |
| 748 | return tup |
| 749 | extra = target + 1 - len(tup.items) |
| 750 | new_items = [] |
| 751 | for it in tup.items: |
| 752 | if not isinstance(it, UnpackType): |
| 753 | new_items.append(it) |
| 754 | continue |
| 755 | unpacked = get_proper_type(it.type) |
| 756 | if isinstance(unpacked, TypeVarTupleType): |
| 757 | instance = unpacked.tuple_fallback |
| 758 | else: |
| 759 | # Nested non-variadic tuples should be normalized at this point. |
| 760 | assert isinstance(unpacked, Instance) |
| 761 | instance = unpacked |
| 762 | assert instance.type.fullname == "builtins.tuple" |
| 763 | new_items.extend([instance.args[0]] * extra) |
| 764 | return tup.copy_modified(items=new_items) |
| 765 | |
| 766 | |
| 767 | def adjust_tuple(left: ProperType, r: ProperType) -> TupleType | None: |
no test coverage detected
searching dependent graphs…