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

Method process_iterator_tuple_assignment

mypyc/irbuild/builder.py:926–995  ·  view source on GitHub ↗
(
        self, target: AssignmentTargetTuple, rvalue_reg: Value, line: int
    )

Source from the content-addressed store, hash-verified

924 self.assign(litem, ritem, line)
925
926 def process_iterator_tuple_assignment(
927 self, target: AssignmentTargetTuple, rvalue_reg: Value, line: int
928 ) -> None:
929 iterator = self.primitive_op(iter_op, [rvalue_reg], line)
930
931 # This may be the whole lvalue list if there is no starred value
932 split_idx = target.star_idx if target.star_idx is not None else len(target.items)
933
934 # Assign values before the first starred value
935 for litem in target.items[:split_idx]:
936 ritem = self.call_c(next_op, [iterator], line)
937 error_block, ok_block = BasicBlock(), BasicBlock()
938 self.add(Branch(ritem, error_block, ok_block, Branch.IS_ERROR))
939
940 self.activate_block(error_block)
941 self.add(
942 RaiseStandardError(
943 RaiseStandardError.VALUE_ERROR, "not enough values to unpack", line
944 )
945 )
946 self.add(Unreachable())
947
948 self.activate_block(ok_block)
949
950 self.assign(litem, ritem, line)
951
952 # Assign the starred value and all values after it
953 if target.star_idx is not None:
954 post_star_vals = target.items[split_idx + 1 :]
955 iter_list = self.primitive_op(to_list, [iterator], line)
956 iter_list_len = self.builtin_len(iter_list, line)
957 post_star_len = Integer(len(post_star_vals))
958 condition = self.binary_op(post_star_len, iter_list_len, "<=", line)
959
960 error_block, ok_block = BasicBlock(), BasicBlock()
961 self.add(Branch(condition, ok_block, error_block, Branch.BOOL))
962
963 self.activate_block(error_block)
964 self.add(
965 RaiseStandardError(
966 RaiseStandardError.VALUE_ERROR, "not enough values to unpack", line
967 )
968 )
969 self.add(Unreachable())
970
971 self.activate_block(ok_block)
972
973 for litem in reversed(post_star_vals):
974 ritem = self.primitive_op(list_pop_last, [iter_list], line)
975 self.assign(litem, ritem, line)
976
977 # Assign the starred value
978 self.assign(target.items[target.star_idx], iter_list, line)
979
980 # There is no starred value, so check if there are extra values in rhs that
981 # have not been assigned.
982 else:
983 extra = self.call_c(next_op, [iterator], line)

Callers 1

assignMethod · 0.95

Calls 14

primitive_opMethod · 0.95
call_cMethod · 0.95
addMethod · 0.95
activate_blockMethod · 0.95
assignMethod · 0.95
builtin_lenMethod · 0.95
binary_opMethod · 0.95
BasicBlockClass · 0.90
BranchClass · 0.90
RaiseStandardErrorClass · 0.90
UnreachableClass · 0.90
IntegerClass · 0.90

Tested by

no test coverage detected