This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tuple __getitem__ limited
Type: Stage:
Components: Interpreter Core Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, loewis, mwh
Priority: normal Keywords:

Created on 2001-09-06 17:11 by loewis, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (6)
msg6421 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2001-09-06 17:11
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))
msg6422 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-09-06 18:08
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.
msg6423 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-06-03 21:01
Logged In: YES 
user_id=6380

See (revived) patch 400998?
msg6424 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-06-13 11:34
Logged In: YES 
user_id=6380

MWH's patch has fixed this now.
msg6425 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-06-13 12:25
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.
msg6426 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-06-13 19:24
Logged In: YES 
user_id=6380

OK, this is now *really* fixed.
History
Date User Action Args
2022-04-10 16:04:25adminsetgithub: 35128
2001-09-06 17:11:54loewiscreate