Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Jul 29 19:31:17 EDT 2010


On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote:

> Steven D'Aprano wrote:
>> [snip]
>>
>> super() is just as explicit as len(), or str.upper(). It says,
>> explicitly, that it will call the method belonging to one or more
>> superclass of the given class.
>>   
> Come on Steven, you're better than this :) . Everybody can accurately
> guess what len and upper are doing without looking at the documentation.
> No one can guess for super without closely looking at the documention,
> or even at some good articles on the net which try to clear things up
> about super. And note there is no such article about len or upper.

super() is complex because the problem it is solving is a hard problem. 
That doesn't make it implicit, any more than (say) itertools.groupby() is 
implicit just because it's complex, or urllib2.request() is implicit just 
because some people don't know much about web protocols and have to read 
articles about it to learn.


> As someone already said in this list, the main problem with super is
> that it tends to refer to the superclass method while in fact it calls
> the next MRO method.

Why do you think that is a problem? That's what it is supposed to do, 
because that's what is needed to correctly implement multiple inheritance.


> "mro" would have been the proper name for "super".

That's your opinion. In any case, whether super() was called super() or 
mro() or aardvark() makes no difference to the functionality or whether 
it is useful.



-- 
Steven



More information about the Python-list mailing list