diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-06-20 14:53:43 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-06-20 14:53:43 (GMT) |
commit | 1ec2fcd16e3c28e1532829d9a4f2cf29f8ebf559 (patch) | |
tree | 2acd565c41af554d9a7ab7b60630d7d456b902d5 /Objects | |
parent | 7b2e2df7406e8d6d29e98388964145b9a5de8316 (diff) | |
download | cpython-1ec2fcd16e3c28e1532829d9a4f2cf29f8ebf559.zip cpython-1ec2fcd16e3c28e1532829d9a4f2cf29f8ebf559.tar.gz cpython-1ec2fcd16e3c28e1532829d9a4f2cf29f8ebf559.tar.bz2 |
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).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/sliceobject.c | 5 |
1 files changed, 3 insertions, 2 deletions
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 @@ 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) |