1.MRO, multiple inheritance, and super()
A class can inherit from more than one base — class C(A, B):. The MRO (Cls.__mro__) is the single lookup path Python computes across all of them. super() walks that path, letting every class in a chain cooperate correctly.
Key features
- class C(A, B): gives C multiple bases — Cls.__mro__ is the exact lookup order
- The MRO is computed via C3 linearization — a real algorithm, not just base order
- super() means "the next class in the MRO after this one," not "my literal parent"
- Cooperative inheritance: every class calls super().__init__(...) so the chain runs
- A conflicting MRO raises TypeError at class definition time, not later
What determines the MRO, and what super() does with it
- class C(A, B) — multiple bases
- C.__mro__ — one linear order: C, A, B, object
- super() — next name in that same order
Command
class C(A, B):
def method(self):
super().method() # calls the NEXT class in C's MRO, not A specificallysuper() means "the next class in the MRO," never "my literal parent" — cooperative inheritance only works when every class in the chain calls it.