Inheritance from builtin list and override of methods.

Michalis Giannakidis mgiann at beta-cae.gr
Tue Nov 28 09:31:38 EST 2006


On Tuesday 28 November 2006 06:12, OKB (not okblacke) wrote:
> Carsten Haese wrote:
> > You can change the behavior of a list's sort method by overriding
> > sort. You can't change the behavior of sort by overriding
> > __getitem__ and __setitem__, because sort does not call __getitem__
> > or __setitem__.
>
>     	Why doesn't it?

I also expected that it did!

I perfectly understand that this adds significant penalty to the execution of 
code. But in the way things are, I have to know ( or guess ?) how its 
function has been implemented. And I cannot handle all cases the same.

If I provided my sort method for my class  in Python, wouldn't this call my 
__getitem__ and __setitem__ methods (considering l[i] = j assignment do)? Can 
this be considered an in consitency?

-- 
Michalis Giannakidis



More information about the Python-list mailing list