Implement __setitem__, __getitem__ and __delitem__ #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The classes
loro.LoroMap,loro.LoroListandloro.LoroMovableListindicate by name that they are Mappings resp. Sequences. However, some methods that are expected of python mappings/sequences are not implemented, especially setitem, getitem and delitem, which allow to use syntax of the formmap["x"] = value,map["x"]anddel map["x"](similar for the sequences). This commit implements these three methods, making the API a bit more pythonic.Even with these methods implemented, the classes are not considered Mappings or Sequences by python, as indicated by
isinstance(loro.LoroMap(), collections.abc.Mapping)andisinstance(loro.LoroList(), collections.abc.Sequence). This requires at least implementing__iter__.The python syntax
l[0:3]calls__getitem__with a slice object, whilel[3]calls__getitem__with an isize. To support both I introducedSliceOrInt. I wasn't quite sure where this struct should live, currently it is defined in bothlist.rsandmutable_list.rs, but I assume it should only be defined once.The code currently also produces the warning
type `list::SliceOrInt<'py>` is more private than the item `list::LoroList::__getitem__.