mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
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:
parent
7b2e2df740
commit
1ec2fcd16e
3 changed files with 24 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue