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

Function translate_vec_create_from_iterable

mypyc/irbuild/expression.py:586–618  ·  view source on GitHub ↗
(
    builder: IRBuilder, vec_type: RVec, arg: Expression, *, capacity: Value | None = None
)

Source from the content-addressed store, hash-verified

584
585
586def translate_vec_create_from_iterable(
587 builder: IRBuilder, vec_type: RVec, arg: Expression, *, capacity: Value | None = None
588) -> Value:
589 line = arg.line
590 item_type = vec_type.item_type
591 if isinstance(arg, OpExpr) and arg.op == "*":
592 if isinstance(arg.left, ListExpr):
593 lst = arg.left
594 other = arg.right
595 elif isinstance(arg.right, ListExpr):
596 lst = arg.right
597 other = arg.left
598 else:
599 assert False
600 assert len(lst.items) == 1
601 other_type = builder.node_type(other)
602 # TODO: is_any_int(...)
603 if is_int64_rprimitive(other_type) or is_int_rprimitive(other_type):
604 length = builder.accept(other)
605 init = builder.accept(lst.items[0])
606 return vec_create_initialized(
607 builder.builder, vec_type, length, init, line, capacity=capacity
608 )
609 assert False, other_type
610 if isinstance(arg, ListExpr):
611 items = []
612 for item in arg.items:
613 value = builder.accept(item)
614 items.append(builder.coerce(value, item_type, line))
615 return vec_create_from_values(builder.builder, vec_type, items, line, capacity=capacity)
616 if isinstance(arg, ListComprehension):
617 return translate_vec_comprehension(builder, vec_type, arg.generator, capacity=capacity)
618 return vec_from_iterable(builder, vec_type, arg, line, capacity=capacity)
619
620
621def vec_from_iterable(

Callers 1

transform_call_exprFunction · 0.85

Calls 12

is_int64_rprimitiveFunction · 0.90
is_int_rprimitiveFunction · 0.90
vec_create_initializedFunction · 0.90
vec_create_from_valuesFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
vec_from_iterableFunction · 0.85
node_typeMethod · 0.80
appendMethod · 0.80
acceptMethod · 0.45
coerceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…