Issue with new-style classes and operators

Greg Ewing see_reply_address at something.invalid
Wed Nov 27 22:57:10 EST 2002


Robin Munn wrote:

> I was experimenting with subclassing list the
> other day and discovered to my surprise that overriding setitem() and
> setslice() had no effect on l.extend(x). This struck me as violating the
> Principle of Least Surprise, *especially* since the documentation had
> said that l.extend(x) was equivalent to l[len(l):len(l)] = x.


I think you're taking the manual too literally. All it's saying
is that, for the built-in list type, the end result of
l.extend(x) is the same as that of l[len(l):len(l)] = x. It's
not meant to imply that it's implemented by actually performing
that action, including going through all the __xxx__ special
methods. Requiring that it did would make it very inefficient.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list