For those converting from UserList to the new
class types, there is a subtle change in behavior
that may violate expectations.
The difference is in the behavior between
a sub-class of list and a sub-class of UserList.
UserList.__getslice__ maintains the class as an
invariant by coercing the object being sliced:
def __getslice__(self, i, j): # from UserList.py
i = max(i, 0); j = max(j, 0)
return self.__class__(self.data[i:j]) #coercion
OTOH, list..__getslice__ alway returns a list
object instead of an object of the sub-class.
To provide a warning, PyChecker can flag any case where:
1. A class derives from list and
2. The class doesn't re-define __getslice__ and
3. An instance makes a slice call.
Log in to post a comment.