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

Method process_sequence_assignment

mypyc/irbuild/builder.py:881–909  ·  view source on GitHub ↗

Process assignment like 'x, y = s', where s is a variable-length list or tuple.

(
        self, target: AssignmentTargetTuple, rvalue: Value, line: int
    )

Source from the content-addressed store, hash-verified

879 return self.coerce(rvalue, rtype, line)
880
881 def process_sequence_assignment(
882 self, target: AssignmentTargetTuple, rvalue: Value, line: int
883 ) -> None:
884 """Process assignment like 'x, y = s', where s is a variable-length list or tuple."""
885 # Check the length of sequence.
886 expected_len = Integer(len(target.items), c_pyssize_t_rprimitive)
887 self.builder.call_c(check_unpack_count_op, [rvalue, expected_len], line)
888
889 # Read sequence items.
890 values = []
891 for i in range(len(target.items)):
892 item = target.items[i]
893 index: Value
894 if is_list_rprimitive(rvalue.type):
895 index = Integer(i, c_pyssize_t_rprimitive)
896 item_value = self.primitive_op(list_get_item_unsafe_op, [rvalue, index], line)
897 elif is_tuple_rprimitive(rvalue.type):
898 index = Integer(i, c_pyssize_t_rprimitive)
899 item_value = self.call_c(tuple_get_item_unsafe_op, [rvalue, index], line)
900 else:
901 index = self.builder.load_int(i)
902 item_value = self.builder.gen_method_call(
903 rvalue, "__getitem__", [index], item.type, line
904 )
905 values.append(item_value)
906
907 # Assign sequence items to the target lvalues.
908 for lvalue, value in zip(target.items, values):
909 self.assign(lvalue, value, line)
910
911 def process_iterator_tuple_assignment_helper(
912 self, litem: AssignmentTarget, ritem: Value, line: int

Callers 1

assignMethod · 0.95

Calls 12

call_cMethod · 0.95
primitive_opMethod · 0.95
assignMethod · 0.95
IntegerClass · 0.90
is_list_rprimitiveFunction · 0.90
is_tuple_rprimitiveFunction · 0.90
lenFunction · 0.85
rangeClass · 0.85
zipFunction · 0.85
appendMethod · 0.80
load_intMethod · 0.45
gen_method_callMethod · 0.45

Tested by

no test coverage detected