super(Child, self).__init__() <=> SomeBaseClass.__init__(self)
It provides a nice shorthand for calling a method on the parent class without having to type it explicitly, which can be long (programmers are lazy) and error-prone. If you change your code later such that Child
is not a SomeBaseClass
anymore but a AnotherBaseClass
instead, you don't have to change the call to the constructor (which is itself required as it will not be called by default)
Note that the case here is obvious, since there is only one base class, but in case where there is an ambiguity (e.g. two or more parent classes), mro prevails (as you would expect I suppose, since that's what it is about):
>>> class A(object):
... def __init__(self):
... print "A"
...
>>> class B(object):
... def __init__(self):
... print "B"
...
>>> class C(A, B):
... def __init__(self):
... super(C, self).__init__()
... print "C"
...
>>> c = C()
A
C
>>> class D(B, A):
... def __init__(self):
... super(D, self).__init__()
... print "D"
...
>>> d = D()
B
D
>>> class CC(A, B):
... def __init__(self):
... B.__init__(self) # Explicitely call B and not A !
... print "CC"
...
>>> cc = CC()
B
CC