[Tutor] quirky multiple inheritance example!?

Kent Johnson kent37 at tds.net
Fri Feb 10 11:53:22 CET 2006


Alan Gauld wrote:
> Having said that I still don't like that mechanism since it makes the 
> behaviour of the subclass depend on the implementation of the 
> superclass. That is, if I choose to create a sub class of someone elses 
> class then a call to super will only work if the other person has 
> written their class with a call to super... not good. Whereas if I call 
> the class init explicitly it works regardless of how the superclass is 
> written.

It's worse than that - with MI if you call __init__() explicitly and the 
base classes call super().__init__(), one of the base class __init__() 
methods will be called twice. See http://fuhm.net/super-harmful/ for an 
example.

super() only works correctly when all the classes involved use it. My 
conclusion is that it is best reserved for the times it is actually 
needed (with diamond MI), and direct calling of the base class method 
should be used everywhere else.

Kent



More information about the Tutor mailing list