Skip to content

Commit

Permalink
fix: revert algorithm for RepeatedComposite insertion. (#101)
Browse files Browse the repository at this point in the history
The sequence pased is referred to as a list but it is not
guarantted to be a Python native list.

Co-authored-by: Bob Hancock <rwh@google.com>
  • Loading branch information
bobhancock and bobhancockg committed Aug 17, 2020
1 parent 203c85e commit ae946aa
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion proto/marshal/collections/repeated.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ def __setitem__(self, key, value):
def insert(self, index: int, value):
"""Insert ``value`` in the sequence before ``index``."""
pb_value = self._marshal.to_proto(self._pb_type, value, strict=True)
self.pb.insert(index, pb_value)

# Protocol buffers does not define a useful insert, so we have
# to pop everything after this point off the list and reload it.
after = [pb_value]
while self.pb[index:]:
after.append(self.pb.pop(index))
self.pb.extend(after)

0 comments on commit ae946aa

Please sign in to comment.