fork download
  1. class Super:
  2. def method(self):
  3. print("method in Super")
  4. try:
  5. super().method()
  6. except:
  7. print("no more classes to call method() on in the mro")
  8.  
  9. class BaseA(Super):
  10. def method(self):
  11. print("method in BaseA")
  12. super().method()
  13.  
  14. class BaseB:
  15. def method(self):
  16. print("method in BaseB")
  17. try:
  18. super().method()
  19. except:
  20. print("no more classes to call method() on in the mro")
  21.  
  22. class BaseC(Super):
  23. def method(self):
  24. print("method in BaseC")
  25. super().method()
  26.  
  27. class DerivedA(BaseA, BaseB, BaseC):
  28. def method(self):
  29. print("method in DerivedA")
  30. super().method()
  31.  
  32. class DerivedB(BaseC, BaseA, BaseB):
  33. def method(self):
  34. print("method in DerivedB")
  35. super().method()
  36.  
  37.  
  38. print([cls.__name__ for cls in DerivedA.mro()])
  39. DerivedA().method()
  40. print()
  41. print([cls.__name__ for cls in DerivedB.mro()])
  42. DerivedB().method()
  43.  
Success #stdin #stdout 0.11s 14100KB
stdin
Standard input is empty
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