Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

Python Multiple Inheritance: How MRO and super() Work

Use a runnable mixin example to see how Python resolves methods, why base class order matters, and when super() continues the chain.

Table of Contents

Python supports multiple inheritance. When more than one base class defines a method, Python uses the class’s method resolution order (MRO) to decide which implementation to call. super() continues the lookup after the class containing the current method, using the MRO of the actual instance.

Class Inheritance in Python (Part 2) Picture 1

See how the order of bases changes a call

class Person:
    def talk(self):
        return 'Hello'


class LoudMixin:
    def talk(self):
        return super().talk().upper()


class LoudPerson(LoudMixin, Person):
    pass


class QuietPerson(Person, LoudMixin):
    pass


print(LoudPerson().talk())   # HELLO
print(QuietPerson().talk())  # Hello
print([cls.__name__ for cls in LoudPerson.__mro__])
# ['LoudPerson', 'LoudMixin', 'Person', 'object']

LoudPerson finds LoudMixin.talk() first. Its super().talk() finds Person.talk(). QuietPerson finds Person.talk() first; that method returns without continuing the chain.

How Python builds a consistent MRO

Python uses C3 linearization. It respects the order of direct bases and preserves the ordering constraints inherited from those bases. If two classes share a parent, that parent appears once. Python raises TypeError at class creation if it can’t satisfy the ordering constraints. See the Python MRO guide for worked hierarchies.

Debugging multiple inheritance

Inspect Class.__bases__ for the direct bases and Class.__mro__ for the full lookup order. That order explains where a method definition is found. Attribute lookup has additional rules for descriptors such as properties. If a chain is meant to run cooperatively, each participating method must accept compatible arguments and pass control along with super(). Review single inheritance and method overrides before adding more than one base.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.