Types and contracts
What is multiple inheritance?
On this page
Multiple inheritance permits a class to inherit from several bases. Python uses a method resolution order to linearise the hierarchy. Inspect Child.__mro__ when debugging a diamond. Cooperative methods that call super() participate in that order and need compatible signatures.
Worked example
Pythonclass Base:
def labels(self):
return []
class Signed(Base):
def labels(self):
return ["signed"] + super().labels()
class Cached(Base):
def labels(self):
return ["cached"] + super().labels()
class Report(Signed, Cached):
pass
assert Report().labels() == ["signed", "cached"]Explore class relationships in the OOP Playground