Issue #3004: Minor fix to slice.indices(). slice(-10).indices(9) now

returns (0, 0, 1) instead of (0, -1, 1), and slice(None, 10, -1).indices(10)
returns (9, 9, -1) instead of (9, 10, -1).
This commit is contained in:
Mark Dickinson 2008-06-20 14:53:43 +00:00
parent 7b2e2df740
commit 1ec2fcd16e
3 changed files with 24 additions and 2 deletions

View file

@ -169,8 +169,9 @@ PySlice_GetIndicesEx(PySliceObject *r, Py_ssize_t length,
else {
if (!_PyEval_SliceIndex(r->stop, stop)) return -1;
if (*stop < 0) *stop += length;
if (*stop < 0) *stop = -1;
if (*stop > length) *stop = length;
if (*stop < 0) *stop = (*step < 0) ? -1 : 0;
if (*stop >= length)
*stop = (*step < 0) ? length - 1 : length;
}
if ((*step < 0 && *stop >= *start)