class BaseA:
def method( self ) :
print ( "method in BaseA" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
class Parent( BaseA) :
def method( self ) :
print ( "method in Parent" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
class BaseB:
def method( self ) :
print ( "method in BaseB" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
class DerivedA( Parent, BaseB) :
def method( self ) :
print ( "method in DerivedA" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
class DerivedB( BaseB, Parent) :
def method( self ) :
print ( "method in DerivedB" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
print ( DerivedA.mro ( ) )
DerivedA( ) .method ( )
print ( )
print ( DerivedB.mro ( ) )
DerivedB( ) .method ( )
print ( )
print ( "'super' in Python is not unpredictable at all." )
print ( "It is unexpected, and DEFINITELY deserving of a wat." )
print ( "But not unpredictable." )
print ( "(btw, multiple inheritance is bad in most cases. "
"don't do it unless you're extra certain of what you're doing. "
"which you probably are not.)" )
Y2xhc3MgQmFzZUE6CiAgICBkZWYgbWV0aG9kKHNlbGYpOgogICAgICAgIHByaW50KCJtZXRob2QgaW4gQmFzZUEiKQogICAgICAgIHRyeToKICAgICAgICAgICAgc3VwZXIoKS5tZXRob2QoKQogICAgICAgIGV4Y2VwdDoKICAgICAgICAgICAgcHJpbnQoIm5vIG1vcmUgY2xhc3NlcyB0byBjYWxsIG1ldGhvZCgpIG9uIGluIHRoZSBtcm8iKQoKY2xhc3MgUGFyZW50KEJhc2VBKToKICAgIGRlZiBtZXRob2Qoc2VsZik6CiAgICAgICAgcHJpbnQoIm1ldGhvZCBpbiBQYXJlbnQiKQogICAgICAgIHRyeToKICAgICAgICAgICAgc3VwZXIoKS5tZXRob2QoKQogICAgICAgIGV4Y2VwdDoKICAgICAgICAgICAgcHJpbnQoIm5vIG1vcmUgY2xhc3NlcyB0byBjYWxsIG1ldGhvZCgpIG9uIGluIHRoZ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luZyBvZiBhIHdhdC4iKQpwcmludCgiQnV0IG5vdCB1bnByZWRpY3RhYmxlLiIpCnByaW50KCIoYnR3LCBtdWx0aXBsZSBpbmhlcml0YW5jZSBpcyBiYWQgaW4gbW9zdCBjYXNlcy4gIgogICAgICAiZG9uJ3QgZG8gaXQgdW5sZXNzIHlvdSdyZSBleHRyYSBjZXJ0YWluIG9mIHdoYXQgeW91J3JlIGRvaW5nLiAiCiAgICAgICJ3aGljaCB5b3UgcHJvYmFibHkgYXJlIG5vdC4pIikK
stdout
[<class '__main__.DerivedA'>, <class '__main__.Parent'>, <class '__main__.BaseA'>, <class '__main__.BaseB'>, <class 'object'>]
method in DerivedA
method in Parent
method in BaseA
method in BaseB
no more classes to call method() on in the mro
[<class '__main__.DerivedB'>, <class '__main__.BaseB'>, <class '__main__.Parent'>, <class '__main__.BaseA'>, <class 'object'>]
method in DerivedB
method in BaseB
method in Parent
method in BaseA
no more classes to call method() on in the mro
'super' in Python is not unpredictable at all.
It is unexpected, and DEFINITELY deserving of a wat.
But not unpredictable.
(btw, multiple inheritance is bad in most cases. don't do it unless you're extra certain of what you're doing. which you probably are not.)