MCPcopy Index your code
hub / github.com/python/mypy / transform_tuple_expr

Function transform_tuple_expr

mypyc/irbuild/expression.py:1169–1193  ·  view source on GitHub ↗
(builder: IRBuilder, expr: TupleExpr)

Source from the content-addressed store, hash-verified

1167
1168
1169def transform_tuple_expr(builder: IRBuilder, expr: TupleExpr) -> Value:
1170 if any(isinstance(item, StarExpr) for item in expr.items):
1171 # create a tuple of unknown length
1172 return _visit_tuple_display(builder, expr)
1173
1174 # create a tuple of fixed length (RTuple)
1175 tuple_type = builder.node_type(expr)
1176 # When handling NamedTuple et. al we might not have proper type info,
1177 # so make some up if we need it.
1178 types = (
1179 tuple_type.types
1180 if isinstance(tuple_type, RTuple)
1181 else [object_rprimitive] * len(expr.items)
1182 )
1183
1184 items = []
1185 for item_expr, item_type in zip(expr.items, types):
1186 reg = builder.accept(item_expr)
1187 item = builder.coerce(reg, item_type, item_expr.line)
1188 if isinstance(item, Register):
1189 temp = Register(item.type)
1190 builder.assign(temp, item, item_expr.line)
1191 item = temp
1192 items.append(item)
1193 return builder.add(TupleSet(items, expr.line))
1194
1195
1196def _visit_tuple_display(builder: IRBuilder, expr: TupleExpr) -> Value:

Callers 1

visit_tuple_exprMethod · 0.90

Calls 13

RegisterClass · 0.90
TupleSetClass · 0.90
anyFunction · 0.85
isinstanceFunction · 0.85
_visit_tuple_displayFunction · 0.85
lenFunction · 0.85
zipFunction · 0.85
node_typeMethod · 0.80
appendMethod · 0.80
acceptMethod · 0.45
coerceMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…