[New-bugs-announce] [issue3004] Bug in slice.indices()
Arnaud Bergeron
report at bugs.python.org
Thu May 29 20:35:55 CEST 2008
New submission from Arnaud Bergeron <abergeron at gmail.com>:
When calling the indices method of a slice object with a negative stop
larger in absolute value than the length passed, the returned stop value
is always -1. It should be 0 when the step is positive.
Current behavior:
>>> slice(-10).indices(11)
(0, 1, 1)
>>> slice(-10).indices(10)
(0, 0, 1)
>>> slice(-10).indices(9)
(0, -1, 1)
>>> slice(-10).indices(8)
(0, -1, 1)
Expected behavior:
>>> slice(-10).indices(11)
(0, 1, 1)
>>> slice(-10).indices(10)
(0, 0, 1)
>>> slice(-10).indices(9)
(0, 0, 1)
>>> slice(-10).indices(8)
(0, 0, 1)
The patch I submit trivially fixes this while preserving the expected -1
when the step is negative like in:
>>> slice(None, -10, -1).indices(8)
(7, -1, -1)
This issue affects python 2.5 and 2.6 at least. I did not test with
other versions.
----------
components: Interpreter Core
files: slice.patch
keywords: patch
messages: 67506
nosy: anakha
severity: normal
status: open
title: Bug in slice.indices()
type: behavior
versions: Python 2.5, Python 2.6
Added file: http://bugs.python.org/file10466/slice.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3004>
_______________________________________
More information about the New-bugs-announce
mailing list