trouble understanding super()

Duncan Booth duncan.booth at invalid.invalid
Mon Jul 31 13:28:49 EDT 2006


John Salerno wrote:

> But after super(D, self).met() is called, doesn't that then call both 
> super(B, self).met() and super(C, self).met()? If so, how does that 
> avoid calling A.met twice? Or is that not what's happening?

If you have an instance of a B then super(B,self).met() will call A.met(), 
but if self is actually an instance of a D, then super(B,self).met() 
actually calls C.met().

That is why super needs both the class and the instance: so it can jump 
sideways across the inheritance diamond instead of always passing calls to 
the base of the current class.



More information about the Python-list mailing list