New submission from Jacob Thalman <jpthal...@gmail.com>:

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, 1)] -> "Getting slice(None, 1, None)"
t[:1] -> (1,)

Overriding __getattribute__ confirms that the overridden __getitem__ is never 
called when syntactic slice syntax is used.

----------
messages: 315551
nosy: jpthalman
priority: normal
severity: normal
status: open
title: Overridden __getitem__ not called on use of slice syntax when inheriting 
from tuple
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33322>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to