Chapter 10: Understanding Method Resolution Order of Inheritance
In this chapter, we will look at the concept of method resolution order (MRO) in Python 3 and how it works on inheritance.
As the name suggests, MRO is the order in which methods of a class get resolved while calling them in a program.
Throughout this chapter, we will look at understanding the MRO through a few examples, how method resolution can go wrong, and how the current Python 3 implementation handles methods defined in a class. We will be making use of MRO throughout this chapter to understand the behavior of code while inheritance is implemented in Python 3.
Why should we understand MRO? In scenarios where we are using multiple classes in Python code, we need to inherit methods from multiple parent classes or superclasses. Understanding the order in which the methods would get resolved from the existing class to its parent class helps in avoiding incorrect method calls. This in turn helps in avoiding...