Whose Method Is It Anyway?
summary
Explains how Python uses the C3 MRO to produce a deterministic superclass linearization, illustrated with pizza/sandwich/calzone diamonds and how lookup walks that linearization left-to-right until it finds a method. Shows the MRO failing with TypeError cannot create a consistent method resolution for conflicting orders and two practical fixes: swap inheritance order or explicitly invoke the desired implementation with Class.method(self, ...). Ends with a mixin example (barista vs short_order_cook) that demonstrates these fixes.
AI-written summary · about
chapters (11)
- 0:00Multiple inheritance fears
- 1:41Python’s multiple inheritance
- 2:45C3 method resolution order
- 6:16Simple inheritance examples
- 9:32Method resolution in complex inheritance
- 12:23Diamond inheritance conflicts
- 14:08Advanced patterns and advice
- 15:33Mixins and multiple inheritance
- 19:24Live coding mixins
- 39:21Mixins pitfalls
- 40:01Conclusion
related talks
57mThe Art of Subclassing
43mThe Zen of Polymorphism: Choosing between isinstance(), methods, and @singledispatch
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
43mGo Ahead, Make a Mess
25mThe Magic of Python
46mOn Being Pythonic
01h 07mWhat Does It All Really Mean
