In the documentation on the Python webpage the method resolution order for classic classes in python is described as a depth-first left-to-right search. I tried to test this with this piece of code:
class A(object):
def __init__(self):
print "Initialized A"
class B(A):
def test():
print "Initialized B"
class C(A):
def __init__(self):
print "Initialized C"
class D(B, C):
def __init__(self):
super(D, self).__init__()
print "Initialized D"
When I create an instance of object D:
D()
I get the result:
Initialized C
Initialized D
While I expected the prints "Initialized A", "Initialized D" since the MRO is depth-first, the initialization is first searched in B, when not found (which is the case) it should go deeper in the hierarchy and look for the function in the base class of B (i.e. A). Can someone give me an explanation why I get the init-function of C instead of that one of A?