Python 2 documentation says that super() function "returns a proxy object that delegates method calls to a parent or sibling class of type."
The questions:
- What is a sibling class in Python?
- How do you delegate a method call to a sibling class?
My presumption was that a sibling for a given class is a class that inherits from the same parent. I drafted the following code to see how a method call can be delegated to a sibling, but it didn't work. What do I do or understand wrong?
class ClassA(object):
def MethodA(self):
print "MethodA of ClassA"
class ClassB(ClassA):
def MethodB(self):
print "MethodB of ClassB"
class ClassC(ClassA):
def MethodA(self):
super(ClassC, self).MethodA()
def MethodB(self):
super(ClassC, self).MethodB()
if __name__ == '__main__':
ClassC().MethodA() # Works as expected
# Fail while trying to delegate method to a sibling.
ClassC().MethodB() # AttirbuteError: 'super' object has no attribute 'MethodB'