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

Ethan Furman ethan at stoneleaf.us
Mon Aug 2 18:37:51 CEST 2010

Steven D'Aprano wrote:
> On Sat, 31 Jul 2010 13:29:25 +0000, Brian Victor wrote:
>> Steven D'Aprano wrote:
>>> On Sat, 31 Jul 2010 14:25:39 +1200, Gregory Ewing wrote:
>>>> Steven D'Aprano wrote:
>>>>>       A
>>>>>      / \
>>>>>     C   B
>>>>>      \ /
>>>>>       D
>>>>>      / \
>>>>>     E   F
>>>>> Yes, a super call might jog left from C to B, but only when being
>>>>> called from one of the lower classes D-F. That's still an upwards
>>>>> call relative to the originator, not sidewards.
>>>> But it's not an upward call relative to the class mentioned in the
>>>> super() call, which is why I say it's misleading.
>>> Which class would that be?
>>> I think I'm going to need an example that demonstrates what you mean,
>>> because I can't make heads or tails of it. Are you suggesting that a
>>> call to super(C, self).method() from within C might call
>>> B.method(self)?
>> Yes, it would.
> [snip example]
> Right, now I see what you mean. I don't have a problem with that 
> behaviour, it is the correct behaviour, and you are making the call from 
> D in the first place, so it *must* call B at some point.
> If you initiate the call from C instead:

I think the point is that when D initiates the  super() chain, and C 
calls super, B will then get its turn -- which has to seem arbitrary 
from C's point of view.


More information about the Python-list mailing list