Message7037

Author jeff.allen
Recipients jeff.allen
Date 2012-04-07.22:03:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1333836226.48.0.959994001113.issue1873@psf.upfronthosting.co.za>
In-reply-to
Content
When attempting to delete an extended slice with a negative step, Jython executes one too many removals. __getslice__ and __delslice__ are inconsistent in the slice they identify:

>jython
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_26
Type "help", "copyright", "credits" or "license" for more information.
>>> a = list(range(0,10))
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a[5:3:-1]
[5, 4]
>>> del a[5:3:-1]
>>> a
[0, 1, 2, 6, 7, 8, 9]
>>> exit()

Just in case I've misunderstood the semantics, I checked CPython:

>c:\Python\26\python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = list(range(0,10))
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a[5:3:-1]
[5, 4]
>>> del a[5:3:-1]
>>> a
[0, 1, 2, 3, 6, 7, 8, 9]
>>> exit()

CPython has the behaviour I expected.

Jython manages to get it right if the stop value is not a "candidate" (and step is necessarily bigger than one):

>jython
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
[Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_26
Type "help", "copyright", "credits" or "license" for more information.
>>> a = list(range(0,10))
>>> a[8:2:-2]
[8, 6, 4]
>>> del a[8:2:-2]
>>> a
[0, 1, 3, 5, 7, 9]
>>> b = list(range(0,10))
>>> b[8:3:-2]
[8, 6, 4]
>>> del b[8:3:-2]
>>> b
[0, 1, 2, 3, 5, 7, 9]
>>> exit()

I noticed this in unit testing another sequence type. The problem is pretty obviously in SequenceIndexDelegate.delSlice(int, int, int).
History
Date User Action Args
2012-04-07 22:03:46jeff.allensetrecipients: + jeff.allen
2012-04-07 22:03:46jeff.allensetmessageid: <1333836226.48.0.959994001113.issue1873@psf.upfronthosting.co.za>
2012-04-07 22:03:46jeff.allenlinkissue1873 messages
2012-04-07 22:03:45jeff.allencreate