MCPcopy Index your code
hub / github.com/python/cpython / expand

Function expand

Tools/cases_generator/analyzer.py:1012–1028  ·  view source on GitHub ↗
(items: list[StackItem], oparg: int)

Source from the content-addressed store, hash-verified

1010 )
1011
1012def expand(items: list[StackItem], oparg: int) -> list[StackItem]:
1013 # Only replace array item with scalar if no more than one item is an array
1014 index = -1
1015 for i, item in enumerate(items):
1016 if "oparg" in item.size:
1017 if index >= 0:
1018 return items
1019 index = i
1020 if index < 0:
1021 return items
1022 try:
1023 count = int(eval(items[index].size.replace("oparg", str(oparg))))
1024 except ValueError:
1025 return items
1026 return items[:index] + [
1027 StackItem(items[index].name + f"_{i}", "", items[index].peek, items[index].used) for i in range(count)
1028 ] + items[index+1:]
1029
1030def scalarize_stack(stack: StackEffect, oparg: int) -> StackEffect:
1031 stack.inputs = expand(stack.inputs, oparg)

Callers 7

expandMethod · 0.85
pickletestMethod · 0.85
test_before_onlyMethod · 0.85
test_after_onlyMethod · 0.85
scalarize_stackFunction · 0.85

Calls 4

enumerateFunction · 0.85
strFunction · 0.85
StackItemClass · 0.85
replaceMethod · 0.45

Tested by 6

expandMethod · 0.68
pickletestMethod · 0.68
test_before_onlyMethod · 0.68
test_after_onlyMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…