Slicing a HyList makes the same kind of object again

This commit is contained in:
Nicolas Dandrimont 2013-06-25 20:08:12 +02:00
parent fad67bd8f5
commit 54757b8316

View File

@ -36,5 +36,16 @@ class HyList(HyObject, list):
def __add__(self, other):
return self.__class__(super(HyList, self).__add__(other))
def __getslice__(self, start, end):
return self.__class__(super(HyList, self).__getslice__(start, end))
def __getitem__(self, item):
ret = super(HyList, self).__getitem__(item)
if isinstance(item, slice):
return self.__class__(ret)
return ret
def __repr__(self):
return "[%s]" % (" ".join([repr(x) for x in self]))