Also known as: MRO, C3 linearisation
The Method Resolution Order (MRO) is the sequence in which Python searches base classes when looking up a method or attribute on an object. In a single-inheritance chain, the MRO is straightforward: child → parent → grandparent → object. With multiple inheritance, Python uses the C3 linearisation algorithm to compute a consistent, predictable order that respects both the local precedence order and the monotonicity constraint.
You can inspect any class's MRO with ClassName.__mro__ (a tuple) or ClassName.mro() (a list). The super() function follows the MRO, not just the direct parent. This is essential for cooperative multiple inheritance: when each class in the hierarchy calls super().method(), the MRO ensures every class's version of the method is called exactly once, in the right order.
The C3 linearisation can fail — if you construct a class hierarchy that has contradictory ordering requirements, Python raises a TypeError at class creation time rather than silently picking an arbitrary order. The diamond problem (where two parents share a common grandparent) is handled correctly by C3: the shared grandparent appears only once in the MRO, at the end. This makes Python's multiple inheritance more predictable than in languages that lack a systematic linearisation algorithm.
Related terms: Inheritance, Mixin
Discussed in:
- Chapter 10: Inheritance and Composition — The Method Resolution Order