[Python-bugs-list] [ python-Bugs-560064 ] inconsistent behavior of __getslice__

noreply@sourceforge.net noreply@sourceforge.net
Fri, 24 May 2002 05:58:45 -0700


Bugs item #560064, was opened at 2002-05-24 06:59
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=560064&group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Cesar Douady (douady)
>Assigned to: Tim Peters (tim_one)
Summary: inconsistent behavior of __getslice__

Initial Comment:
The following trace shows what I mean:
>>> help(str.__getslice__)
Help on wrapper_descriptor:

__getslice__(...)
    x.__getslice__(i, j) <==> x[i:j]
>>> 'ab'[-1]
'b'
>>> 'ab'.__getitem__(-1)
'b'
>>> 'ab'[-2:-1]
'a'
>>> 'ab'.__getslice__(-2,-1)
''

that is, __getslice__ does not add the length of the
sequence to its arguments when they are negative as
indexing with [:] does.
This contradicts the docstring which says __getslice__
is equivalent to indexing.
The same behavior applies to lists.

Note that __getitem__ does it right.

This bug may be linked to bug 473985 ('str, __getitem__
and slices') but should be much easier to fix.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-05-24 07:58

Message:
Logged In: YES 
user_id=80475

Tim,  I attached a tiny patch which fixes the behavior for 
strings.  I've also tried out the same change in listobject.c 
and unicodeobject.c.  Is this the right this to do or are 
there more subtleties to this than meet the eye?


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=560064&group_id=5470