MCPcopy Create free account
hub / github.com/python/mypy / expand_tuple_if_possible

Function expand_tuple_if_possible

mypy/meet.py:746–764  ·  view source on GitHub ↗
(tup: TupleType, target: int)

Source from the content-addressed store, hash-verified

744
745
746def 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
767def adjust_tuple(left: ProperType, r: ProperType) -> TupleType | None:

Callers 1

are_tuples_overlappingFunction · 0.85

Calls 6

get_proper_typeFunction · 0.90
lenFunction · 0.85
isinstanceFunction · 0.85
appendMethod · 0.80
extendMethod · 0.80
copy_modifiedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…