super() and multiple inheritance failure

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Sep 26 06:48:08 CEST 2009


On Fri, 25 Sep 2009 21:03:09 -0700, Michele Simionato wrote:

> On Sep 26, 4:36 am, Steven D'Aprano <st... at REMOVE-THIS-
> cybersource.com.au> wrote:
>> I don't understand why I'm getting the following behaviour when using
>> super() with multiple inheritance.
> 
> super is working as intended. If you do not want cooperative methods,
> don't use super and call directly the superclass. 

Gotcha.

Is there a standard name for what I'm trying to do, versus what super() 
does? I assume the term for what super() does is "cooperative multiple 
inheritance". What should I call what I'm doing? "Non-cooperative MI" 
perhaps?


> I usually recommend avoiding multiple inheritance altogether.

In my case, PClass and NClass are actually private classes, and it seemed 
like a nice way to avoid having to fill MyClass with slightly-different 
versions of each method to deal with slight variations in the arguments. 
I'm aiming for some sort of polymorphic inheritance: in a method, if the 
argument meets some condition, inherit from PClass, if it meets another 
condition inherit from NClass, and so on. Is there are standard name for 
this idea?


> You may want to read "Things to know about super":
> 
> http://www.artima.com/weblogs/viewpost.jsp?thread=236275
> http://www.artima.com/weblogs/viewpost.jsp?thread=236278
> http://www.artima.com/weblogs/viewpost.jsp?thread=237121

Nice, thank you. It will take me a while to digest all that, this is my 
first attempt at deliberate multiple inheritance, and obviously my 
expectations were completely different.



-- 
Steven



More information about the Python-list mailing list