Supported updates of an array by negative index

This commit is contained in:
Dmitry Voronenkov 2019-06-18 16:13:29 +03:00
parent bb0b1e88ef
commit 6a4c342e45

View File

@ -108,6 +108,9 @@ class BaseList(list):
super(BaseList, self).__init__(list_items) super(BaseList, self).__init__(list_items)
def __getitem__(self, key): def __getitem__(self, key):
# change index to positive value because MongoDB does not support negative one
if isinstance(key, int) and key < 0:
key = len(self) + key
value = super(BaseList, self).__getitem__(key) value = super(BaseList, self).__getitem__(key)
if isinstance(key, slice): if isinstance(key, slice):