[Tutor] super() with Multiple Inheritance

Alan Gauld alan.gauld at btinternet.com
Fri Apr 15 03:35:03 CEST 2011


"Steven D'Aprano" <steve at pearwood.info> wrote

>> No, because super returns whatever the superclass
>> method returns. Which in init() is usually None.
>
> No, super returns a proxy object that encapsulates knowledge of the 
> superclasses of the argument (usually "self", but not necessarily).

> >>> b = B()
> >>> s = super(B, b)
> >>> s
> <super: <class 'B'>, <B object>>

I stand corrected. And I'm sure Guido knows why he did it
that way, but it adds to the complexity in the way Python
handles this stuff. I know SmallTalk has it simpler because
it only has to deal with single inheritance but the Python
super() implementation really, really feels flaky to me,
its one of the few Python features I don't enjoy using.

> If you look up a method, and *call* that method, then of course the 
> complete chain of super::method lookup::method call will return 
> whatever the method itself returns. But that's different from saying 
> that super itself returns (say) None.

True, although it feels like that to the programmer.
But under the hood its different and potentially acts different.
Thanks for pointing that out - I'm gonna have to give it
some (more) thought. I keep trying to embrace super()
but every time I try I just find more issues with it. yek!

Alan G. 




More information about the Tutor mailing list