class First(object):
def __init__(self):
print("first")
class Second(First):
def __init__(self):
print("second")
class
If we apply the C3 linearization algorithm:
i) take the head of the first list.
ii) if this head is not in the tail of any of the other lists, then add it to the linearization of C and remove it from the lists in the merge
iii) otherwise look at the head of the next list and take it if it is a good head
iv) Then repeat the operation until all the class is removed or it is impossible to find good heads.
O : is the object class
L[First] = First O
L[Second] = Second + merge(L[First], First)
Now solving L[Second]
L[Second] = Second + merge(FirstO, First)
First is the head in list FirstO and in the list First, so it is a good head.
L[Second] = Second + First + merge(O)
O is the only head in the list and it is good head
L[Second] = Second + First + O
L[Second] = Second First O
L[Third] = Third + merge(L[First], L[Second], FirstSecond)
Now solving L[Third]
L[Third] = Third + merge(FirstO, SecondFirstO, FirstSecond)
L[Third] = Third + impossible to find good heads.
First is the head in the list FirstO but it is the tail in the list SecondFirstO, Second is the head in the list SecondFirstO but it is the tail in the list FirstSecond and O is tail in both the list FirstO, SecondFirstO so it is not possible to find good heads.
To be "consistent" the MRO should satisfy these constraints:
Your proposed hierarchy does not have any possible ordering meeting these constraints. Because Third is defined to inherit from First before Second, First should come before Second in the MRO. But because Second inherits from First, Second should come before First in the MRO. This contradiction cannot be reconciled.
You can read more about the precise method Python uses to compute the MRO, which is called the C3 linearization algorithm.