I was reading Python Multiple Inheritance (on Programiz) and then I found this StackOverflow question, Method Resolution Order (MRO) in new-style classes? but in this question some programmers like Alex Martelli said it uses the depth-first approach, and I have a doubt.
Example:
class H():
def m(self):
print("H")
class G(H):
def m(self):
print("G")
super().m()
class I(G):
def m(self):
print("I")
super().m()
class F(H):
def m(self):
print("F")
super().m()
class E(H):
def m(self):
print("E")
super().m()
class D(F):
def m(self):
print("D")
super().m()
class C(E, F, G):
def m(self):
print("C")
super().m()
class B():
def m(self):
print("B")
super().m()
class A(B, C, D):
def m(self):
print("A")
super().m()
x = A()
x.m()
So if I build a graph based on the MRO then according to depth-first it should follow this:
and path should be:
A-->B-->C-->E-->F-->G-->D-->H
But if you run above code you will get:
A
B
C
E
D
F
G
H
Because it is following this path:
A-->B-->C-->E-->D-->F-->G-->H
Now I have confusion about node "D" or class "D" in depth first it comes when earlier and in MRO it comes later.
What's going on here?