MRO
The method resolution order (MRO) is the linear sequence of classes Python searches when looking up an attribute on a class or instance. Class.__mro__ shows it. super() walks it.
Detailed Explanation
Attribute lookup has to have a winner. If LoggedHandler inherits LoggerMixin and Handler, and both define dispatch, one method runs. The MRO is that decision, computed once when the class is created, using the C3 linearisation algorithm.
C3 keeps three promises. A class appears before its parents. The local base list is respected: class C(A, B) puts A before B. The order of parents in each ancestor is preserved. If those promises cannot be satisfied, class creation raises TypeError: Cannot create a consistent method resolution order. That error is a gift; it means your inheritance graph is contradictory.
You read the MRO as a tuple starting with the class itself and ending with object. Lookup walks left to right and stops at the first class that defines the name. Instance attributes still win first; the MRO is for class-level names (methods, class attributes, descriptors).
super() is an MRO walker, not a synonym for "my first parent". super().dispatch() in LoggerMixin continues after LoggerMixin in the instance's class MRO. That is why the same mixin can sit in front of different concrete classes and still reach the right next method.
Class.mro() returns a list. Class.__mro__ is the tuple. They agree. inspect.getmro(Class) is the same idea. When the wrong method runs, print the MRO before you rewrite the classes.
Single inheritance still has an MRO: (Child, Parent, object). You can ignore it until you add a second base. Once you do, the MRO is the spec.
Code Examples
class A:
def name(self) -> str:
return "A"
class B(A):
def name(self) -> str:
return "B+" + super().name()
class C(A):
def name(self) -> str:
return "C+" + super().name()
class D(B, C):
pass
print(D.__mro__)
# (<class 'D'>, <class 'B'>, <class 'C'>, <class 'A'>, <class 'object'>)
print(D().name()) # B+C+A# An inconsistent graph fails at class creation.
class X:
pass
class Y(X):
pass
# class Z(X, Y): # TypeError: Cannot create a consistent MRO
# passCommon Gotchas
`super()` is not `Parent`
in a diamond it may call a sibling, not the class you subclassed. That is correct C3 behaviour.
Changing base order changes the MRO
`class D(C, B)` would prefer `C` first. Tests that pass with one order fail with the other.
A class attribute on a later MRO class is hidden
`B.flag = True` wins over `C.flag` if `B` is earlier, even if you "meant" `C`.
`object` is always last
custom `__getattribute__` on a root class affects everything. Do not put application logic on a universal base.