I'm trying to create a class that behaves exactly as a slice, but that implements the __add__
method to combine multiple slices in a single slice.
A simple mockup could be:
class cumslice(slice):
def __add__(self, other):
s1 = self.start
e1 = self.end
st1 = self.step
s2 = other.start
e2 = other.end
st2 = other.step
s = s1 + st1*s2
st = st1*st2
e = min([e1, s1 + st1*e2])
return cumslice(s, e, st)
(note that we need some if
to handles None
values.)
However the code above returns
TypeError: type 'slice' is not an acceptable base type
Is it possible to do something like this without reimplementing the slice type from scratch?