class Super:
def method( self ) :
print ( "method in Super" )
try :
super ( ) .method ( )
except :
print ( "no more classes to call method() on in the mro" )
class BaseA( Super) :
def method( self ) :
print ( "method in BaseA" )
super ( ) .method ( )
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 BaseC( Super) :
def method( self ) :
print ( "method in BaseC" )
super ( ) .method ( )
class DerivedA( BaseA, BaseB, BaseC) :
def method( self ) :
print ( "method in DerivedA" )
super ( ) .method ( )
class DerivedB( BaseC, BaseA, BaseB) :
def method( self ) :
print ( "method in DerivedB" )
super ( ) .method ( )
print ( [ cls.__name__ for cls in DerivedA.mro ( ) ] )
DerivedA( ) .method ( )
print ( )
print ( [ cls.__name__ for cls in DerivedB.mro ( ) ] )
DerivedB( ) .method ( )
Y2xhc3MgU3VwZXI6CiAgICBkZWYgbWV0aG9kKHNlbGYpOgogICAgICAgIHByaW50KCJtZXRob2QgaW4gU3VwZXIiKQogICAgICAgIHRyeToKICAgICAgICAgICAgc3VwZXIoKS5tZXRob2QoKQogICAgICAgIGV4Y2VwdDoKICAgICAgICAgICAgcHJpbnQoIm5vIG1vcmUgY2xhc3NlcyB0byBjYWxsIG1ldGhvZCgpIG9uIGluIHRoZSBtcm8iKQoKY2xhc3MgQmFzZUEoU3VwZXIpOgogICAgZGVmIG1ldGhvZChzZWxmKToKICAgICAgICBwcmludCgibWV0aG9kIGluIEJhc2VBIikKICAgICAgICBzdXBlcigpLm1ldGhvZCgpCgpjbGFzcyBCYXNlQjoKICAgIGRlZiBtZXRob2Qoc2VsZik6CiAgICAgICAgcHJpbnQoIm1ldGhvZCBpbiBCYXNlQiIpCiAgICAgICAgdHJ5OgogICAgICAgICAgICBzdXBlcigpLm1ldGhvZCgpCiAgICAgICAgZXhjZXB0OgogICAgICAgICAgICBwcmludCgibm8gbW9yZSBjbGFzc2VzIHRvIGNhbGwgbWV0aG9kKCkgb24gaW4gdGhlIG1ybyIpCgpjbGFzcyBCYXNlQyhTdXBlcik6CiAgICBkZWYgbWV0aG9kKHNlbGYpOgogICAgICAgIHByaW50KCJtZXRob2QgaW4gQmFzZUMiKQogICAgICAgIHN1cGVyKCkubWV0aG9kKCkKCmNsYXNzIERlcml2ZWRBKEJhc2VBLCBCYXNlQiwgQmFzZUMpOgogICAgZGVmIG1ldGhvZChzZWxmKToKICAgICAgICBwcmludCgibWV0aG9kIGluIERlcml2ZWRBIikKICAgICAgICBzdXBlcigpLm1ldGhvZCgpCgpjbGFzcyBEZXJpdmVkQihCYXNlQywgQmFzZUEsIEJhc2VCKToKICAgIGRlZiBtZXRob2Qoc2VsZik6CiAgICAgICAgcHJpbnQoIm1ldGhvZCBpbiBEZXJpdmVkQiIpCiAgICAgICAgc3VwZXIoKS5tZXRob2QoKQoKCnByaW50KFtjbHMuX19uYW1lX18gZm9yIGNscyBpbiBEZXJpdmVkQS5tcm8oKV0pCkRlcml2ZWRBKCkubWV0aG9kKCkKcHJpbnQoKQpwcmludChbY2xzLl9fbmFtZV9fIGZvciBjbHMgaW4gRGVyaXZlZEIubXJvKCldKQpEZXJpdmVkQigpLm1ldGhvZCgpCg==
stdout
['DerivedA', 'BaseA', 'BaseB', 'BaseC', 'Super', 'object']
method in DerivedA
method in BaseA
method in BaseB
method in BaseC
method in Super
no more classes to call method() on in the mro
['DerivedB', 'BaseC', 'BaseA', 'Super', 'BaseB', 'object']
method in DerivedB
method in BaseC
method in BaseA
method in Super
method in BaseB
no more classes to call method() on in the mro