I found this code in a 3rd party module which was ignoring foo[::step]
or key.step
in this case.
def __getitem__(self, key):
if isinstance(key, slice):
return self._sub_slice(key.start, key.stop)
if self._is_in_range(key):
return self._tree[key]
else:
raise KeyError(key)
While supporting steps would be ideal, assuming this isn't going to be supported, I'd like to add an exception, otherwise foo[a:b:-1]
for eg will ignore the -1
in the slice.
eg:
if key.step not in {None, 1}:
raise Exception("only a step size of 1 is supported")
So my question is, for valid but unsupported slice steps, which exception type should be used?