I'm trying to subclass the list
builtin, but my new list is acting strangely and i believe __setslice__
& __getslice__
are to blame. The changes i make to the list
aren't invasive and are really behind-the-scenes; so to the user, it should behave exactly like a regular list
.
The problem comes when the user wants to clear a list. I executed the following test (at repl.it) and got a strange result:
class IHateCoding(list):
def __getslice__(self, *args):
print 'get', args
return super(IHateCoding, self).__getslice__(*args)
def __setslice__(self, *args):
print 'set', args
super(IHateCoding, self).__setslice__(*args)
>>> l = IHateCoding()
>>> l.extend(xrange(5))
>>> l[:] = []
set (0, 2147483647, [])
Where does this 2147483647
value come from, and why does it return a view?
EDIT:
There's one more strange output i've discovered. Can anyone explain this?
>>> l[:-1]
get (0, 2) #Expected `-1`