enable slicing of SSZ lists/vectors
This commit is contained in:
parent
4dcfee2d2c
commit
d8f470bb4a
|
@ -295,13 +295,14 @@ class BaseList(list, Elements):
|
||||||
cls = self.__class__
|
cls = self.__class__
|
||||||
return f"{cls.__name__}[{cls.elem_type.__name__}, {cls.length}]({', '.join(str(v) for v in self)})"
|
return f"{cls.__name__}[{cls.elem_type.__name__}, {cls.length}]({', '.join(str(v) for v in self)})"
|
||||||
|
|
||||||
def __getitem__(self, i) -> SSZValue:
|
def __getitem__(self, k) -> SSZValue:
|
||||||
if i < 0:
|
if isinstance(k, int): # check if we are just doing a lookup, and not slicing
|
||||||
raise IndexError(f"cannot get item in type {self.__class__} at negative index {i}")
|
if k < 0:
|
||||||
if i > len(self):
|
raise IndexError(f"cannot get item in type {self.__class__} at negative index {k}")
|
||||||
raise IndexError(f"cannot get item in type {self.__class__}"
|
if k > len(self):
|
||||||
f" at out of bounds index {i}")
|
raise IndexError(f"cannot get item in type {self.__class__}"
|
||||||
return super().__getitem__(i)
|
f" at out of bounds index {k}")
|
||||||
|
return super().__getitem__(k)
|
||||||
|
|
||||||
def __setitem__(self, k, v):
|
def __setitem__(self, k, v):
|
||||||
if k < 0:
|
if k < 0:
|
||||||
|
|
Loading…
Reference in New Issue