[issue33322] Overridden __getitem__ not called on use of slice syntax when inheriting from tuple

2018-04-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: In Python 2 things are more complex than in Python 3. You have to define __getslice__ for handling the case of literal slices. This was fixed in Python 3. -- nosy: +serhiy.storchaka

[issue33322] Overridden __getitem__ not called on use of slice syntax when inheriting from tuple

2018-04-21 Thread Steven D'Aprano
Steven D'Aprano added the comment: In Python 2, you have to override __getslice__ as well as __getitem__. Try this instead: class MyTuple(tuple): def __getitem__(self, pos): print "get item {}".format(pos) return super(MyTuple,

[issue33322] Overridden __getitem__ not called on use of slice syntax when inheriting from tuple

2018-04-21 Thread Jacob Thalman
New submission from Jacob Thalman : class MyTuple(tuple): def __getitem__(self, item): print "Getting {}".format(item) t = MyTuple((1, 2)) t[0] -> "Getting 0" t[1] -> "Getting 1" t[slice(None)] -> "Getting slice(None, None, None)" t[:] -> (1, 2) t[slice(None,