Skip to content

Commit

Permalink
len_slice: Catch more cases where length is unknown.
Browse files Browse the repository at this point in the history
  • Loading branch information
jakirkham committed Dec 9, 2016
1 parent 7deb3e8 commit 725879b
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions kenjutsu/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ def len_slice(a_slice, a_length=None):

new_slice_size = 0
if isinstance(new_slice, slice):
if new_slice.stop is None:
if new_slice.step > 0:
if (new_slice.step > 0 and new_slice.start >= 0 and
(new_slice.stop is None or new_slice.stop < 0)):
raise UnknownSliceLengthException(
"Cannot determine slice length without a defined end"
"Cannot determine slice length without a defined start"
" point. The reformatted slice was %s." % repr(new_slice)
)
else:
new_slice = slice(new_slice.start, -1, new_slice.step)
elif (new_slice.step < 0 and new_slice.start < 0 and
(new_slice.stop is None or new_slice.stop >= 0)):
raise UnknownSliceLengthException(
"Cannot determine slice length without a defined start"
" point. The reformatted slice was %s." % repr(new_slice)
)

if new_slice.step < 0 and new_slice.stop is None:
new_slice = slice(new_slice.start, -1, new_slice.step)

new_slice_diff = float(new_slice.stop - new_slice.start)

Expand Down

0 comments on commit 725879b

Please sign in to comment.