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