super
is not a universal replacement for calling a method in a parent base class; it requires that classes be designed cooperatively. This means that every class needs to call super().performLogic
, just in case it is not the last element of some class's MRO.
Ultimately, there has to be some class at the end of the method resolution order which cannot call super().peformLogic()
, either because it is the last class on the list or the next call would be delegated to a class (like object
) which does not define performLogic
. In this case, you'll have to provide such a root class yourself.
class LogicPerformer:
def performLogic(self):
# No call to super; the buck stops here, because object
# doesn't have this method
print("In LogicPerformer")
class InheritedClass1(LogicPerformer):
def performLogic(self):
print("In InheritedClass1")
super().performLogic()
class InheritedClass2(LogicPerformer):
def performLogic(self):
print("In InheritedClass1")
super().performLogic()
class SomeClass(InheritedClass1, InheritedClass2):
def performLogic(self):
print("In SomeClass")
super().performLogic()
a = SomeClass()
print(SomeClass.__mro__)
a.performLogic()