[Python-bugs-list] [ python-Bugs-459235 ] tuple __getitem__ limited
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 13 Jun 2002 12:24:59 -0700
Bugs item #459235, was opened at 2001-09-06 13:11
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=459235&group_id=5470
Category: Type/class unification
Group: Python 2.2
>Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Martin v. Löwis (loewis)
Assigned to: Guido van Rossum (gvanrossum)
Summary: tuple __getitem__ limited
Initial Comment:
The __getitem__ of a tuple does not support the
extended slicing. That makes it difficult to delegate
from an object's __getitem__ to a builtin container,
which ought to work through delegating __getitem__
<pre>
class GI:
def __getitem__(self,a):
print a
a = GI()
a[1:2]
(1,2,3,4).__getitem__(slice(1,2,None))
</pre>
gives
slice(1, 2, None)
Traceback (most recent call last):
File "bar.py", line 7, in ?
(1,2,3,4).__getitem__(slice(1,2,None))
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-13 15:24
Message:
Logged In: YES
user_id=6380
OK, this is now *really* fixed.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2002-06-13 08:25
Message:
Logged In: YES
user_id=6656
Um, are you sure?
I still get
>>> (1,2,3).__getitem__(slice(1,2,3))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: an integer is required
[19426 refs]
Though:
>>> (1,2,3)[slice(1,2,3)]
(2,)
[19429 refs]
which is an improvement.
I guess this is for the same reason as #473985 is still open.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-13 07:34
Message:
Logged In: YES
user_id=6380
MWH's patch has fixed this now.
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2002-06-03 17:01
Message:
Logged In: YES
user_id=6380
See (revived) patch 400998?
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-09-06 14:08
Message:
Logged In: YES
user_id=6380
This is not just the __getitem__ -- t[...] also has this
problem.
As a workaround, you can define __getslice__ or parse the
slice() object yourself.
I'll eventually get around to fixing this, but it's a bit
messy.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=459235&group_id=5470