[issue3004] Bug in slice.indices()

Mark Dickinson report at bugs.python.org
Fri Jun 20 12:49:17 CEST 2008


Mark Dickinson <dickinsm at gmail.com> added the comment:

Here's a new patch that incorporates Arnaud's fix and tests, together with 
a few extra tests.

While I expect that this change will affect very little code, I think it's 
the right thing to do, because:

 - start and stop are now processed identically, making the source code
   easier to understand, and the behaviour easier to explain.

 - expected invariants now hold even in corner cases;  for example, after:

start, stop, step = my_slice.indices(length)

it's guaranteed that

0 <= start <= stop <= length    if step is positive, and
length-1 >= start >= stop >= -1 if step is negative.

However, I'd like a second opinion from another core developer before 
checking this in.

Added file: http://bugs.python.org/file10670/issue3004.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3004>
_______________________________________


More information about the Python-bugs-list mailing list