Skip to content

Commit

Permalink
reformat_slice: Handle an empty slice caused by stop.
Browse files Browse the repository at this point in the history
Just as a stop value of 0 for a slice with a positive step size will
result in an empty slice, a stop value of -1 or positive equivalent
(given the length is known) will result in an empty slice given a
negative step size. This change handles that case and converts the slice
to a trivial empty slice to make it easier to recognize.
  • Loading branch information
jakirkham committed Dec 5, 2016
1 parent e5fd4cb commit 123c6cb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions kenjutsu/kenjutsu.py
Expand Up @@ -120,6 +120,9 @@ def reformat_slice(a_slice, a_length=None):
elif (step > 0) and (stop == 0):
start = stop = 0
step = 1
elif (step < 0) and (stop == -1):
start = stop = 0
step = 1
elif stop_i and (start >= 0) and (stop >= 0):
if (step > 0) and (start > stop):
start = stop = 0
Expand Down

0 comments on commit 123c6cb

Please sign in to comment.