I was looking at a code which a Parent class calls super:
class ParentClass:
def __init__(self):
super(ParentClass, self).__init__()
I don't understand why would someone call super on itself and how does this not get stuck on a recursive loop. Is there something in the background of Python mechanisms that I'm missing?
superis to find the parent class of the current class, so it needs to know the current class (what you likely mean by "itself"). Note that Python3 allows parameter-freesuper()calls in most cases.superis the class to start looking from. In a simple case this would resolve toobject.__init__, but allows this class to cooperate in a multiple-inheritance case.__init__adn we are calling super which does not have an upper level to go since we are in the base class, why does this work? I thought when we are at the parent, super would point again to the parent which is not the case. Can someone explain what is happening behind the scenes in this case since I can't find any information about using super inside parent class (it does not have any other level up)