Issue 459235: tuple getitem limited (original) (raw)

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

class GI:
    def __getitem__(self,a):
        print a

a = GI()
a[1:2]
(1,2,3,4).__getitem__(slice(1,2,None))

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 "", 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.