[issue42467] slice().indices() returns incorrect values

misianne report at bugs.python.org
Wed Nov 25 15:54:21 EST 2020


New submission from misianne <rotenca at gmail.com>:

I have a problem with slice().indices():

x=[0,1,2,3,4,5,6,7,8,9]*10
x[-91:-101:-3] # == [9, 6, 3, 0] OK!
x[slice(*slice(-91,-101,-3).indices(len(x)))] # == [] WRONG!

This is correct:

x[-91:-100:-3] # == [9, 6, 3] OK!
x[slice(*slice(-91,-100,-3).indices(len(x)))] # == [9, 6, 3] OK!

This is not:

x[-91:-101:-3] # == [9, 6, 3, 0] OK!
x[slice(*slice(-91,-101,-3).indices(len(x)))] # == [] WRONG!

The problem is that 
	slice(-91,-101,-3).indices(len(x))
returns:
	(9,-1,-3)
which result in an empty list, while:
	(9,None,-3)
gives the correct result.

----------
components: Interpreter Core
messages: 381862
nosy: misianne
priority: normal
severity: normal
status: open
title: slice().indices() returns incorrect values
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42467>
_______________________________________


More information about the Python-bugs-list mailing list