The following methods can be defined to further emulate sequence objects. Immutable sequences methods should only define __getslice__(); mutable sequences, should define all three three methods.
Called to implement evaluation of self[i:j]
.
The returned object should be of the same type as self. Note
that missing i or j in the slice expression are replaced
by zero or sys.maxint
, respectively. If negative indexes are
used in the slice, the length of the sequence is added to that index.
If the instance does not implement the __len__() method, an
AttributeError is raised.
No guarantee is made that indexes adjusted this way are not still
negative. Indexes which are greater than the length of the sequence
are not modified.
If no __getslice__() is found, a slice
object is created instead, and passed to __getitem__() instead.
self[i:j]
.
Same notes for i and j as for __getslice__().
This method is deprecated. If no __setslice__() is found, a slice object is created instead, and passed to __setitem__() instead.
self[i:j]
.
Same notes for i and j as for __getslice__().
This method is deprecated. If no __delslice__() is found, a slice
object is created instead, and passed to __delitem__() instead.
Notice that these methods are only invoked when a single slice with a single colon is used, and the slice method is available. For slice operations involving extended slice notation, or in absence of the slice methods, __getitem__(), __setitem__() or __delitem__() is called with a slice object as argument.