class First(object):
def __init__(self):
print("first")
class Second(First):
def __init__(self):
print("second")
class Third(First, Second):
def __init__(self):
print("third")
Why can't Python create a consistent MRO? It seems to me it's pretty clear:
But if you try it out:
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases First, Second
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.