class A: def process(self): print('A process()') class B: pass class C(A, B): pass obj = C() obj.process() print(C.mro()) # print MRO for class C
A process()
[<class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>]
class A: def process(self): print('A process()') class B: def process(self): print('B process()') class C(A, B): pass obj = C() obj.process()
class A: def process(self): print('A process()') class B: def process(self): print('B process()') class C(A, B): def process(self): print('C process()') class D(C,B): pass obj = D() obj.process() print(D.mro())
C process() [<class '__main__.D'>, <class '__main__.C'>, <class '__main__.A'>, <class '__main__.B'>, <class 'object'>]
class A: def process(self): print('A process()') class B(A): pass class C(A): def process(self): print('C process()') class D(B,C): pass obj = D() obj.process()
C process() [<class '__main__.D'>, <class '__main__.B'>, <class '__main__.C'>, <class '__main__.A'>, <class 'object'>]
D -> B -> A -> C -> A
D -> B-> A -> object -> C -> A -> object
D -> B -> C -> A -> object
class A: def process(self): print('A process()') class B(A): def process(self): print('B process()') class C(A, B): pass obj = C() obj.process()
TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B
C -> A -> B -> A
C -> B -> A