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).
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 075418e..8748fed 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -169,8 +169,9 @@
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)