Python Multiple Inheritance: Use MRO and super()

A class may need behavior or attributes from more than one base class. Multiple inheritance lets it list those direct bases, and the method resolution order (MRO) gives Python the sequence it searches for inherited methods.

I’ll show how to inspect the MRO and follow a method call through super().

TL;DR

Python resolves inherited methods through a method resolution order (MRO), an ordered list of classes. A call to super() continues that list after the class where the call appears. It does not name one permanent parent.

  • Inspect ClassName.__mro__ to see the order Python computed.
  • Use super() when the classes are designed to cooperate and each override should pass control along.
  • Use a named base call only when you intend to target that implementation directly.

What Is Python Multiple Inheritance?

Multiple inheritance lets one class list more than one direct base because the derived class needs behavior or attributes from each. The new class is derived, and the listed classes are its bases. It can also define its own implementation.

class Base:
    pass


class Left(Base):
    pass


class Right(Base):
    pass


class Child(Left, Right):
    pass


print("Direct bases:", ", ".join(base.__name__ for base in Child.__bases__))
print("MRO:", " -> ".join(cls.__name__ for cls in Child.__mro__))
pankaj@askpython:~$ python3 inheritance_shape_demo.py
Direct bases: Left, Right
MRO: Child -> Left -> Right -> Base -> object
Terminal output shows direct bases and the computed MRO for a diamond
Child’s first line lists its direct bases. The next line shows its full MRO.

The first line prints Child.__bases__, its two immediate parents. The second prints Child.__mro__, which includes inherited classes and object.

Shape or roleRelationshipWhat to notice
Single inheritanceOne direct baseA child extends one parent.
Multilevel inheritanceA base is itself derived from another classThe relationship forms a chain.
DiamondTwo branches share an ancestorThe shared class is reachable by more than one path.
MixinA small capability class is added as a baseOne focused behavior can be shared across class families.

The official Python class tutorial describes C3 linearization, which places each class before its ancestors, preserves local base order, and lists shared ancestors once.

Python classes inherit from object, so multiple branches share an endpoint.

How to Trace Python Multiple Inheritance and super()

Use a small hierarchy to watch the lookup and calls, then compare them with a deliberately incompatible ordering. The source file and terminal capture below show the exact run.

Step 1: Build a cooperative diamond

Run python3 multiple_inheritance_demo.py to watch a cooperative diamond, explicit base calls, and a deliberately incompatible ordering.

class Base:
    def action(self):
        print("Base")


class Left(Base):
    def action(self):
        print("Left")
        super().action()


class Right(Base):
    def action(self):
        print("Right")
        super().action()


class Cooperative(Left, Right):
    def action(self):
        print("Cooperative")
        super().action()


class ExplicitLeft(Base):
    def action(self):
        print("Left")
        Base.action(self)


class ExplicitRight(Base):
    def action(self):
        print("Right")
        Base.action(self)


class ExplicitChild(ExplicitLeft, ExplicitRight):
    def action(self):
        print("ExplicitChild")
        ExplicitLeft.action(self)
        ExplicitRight.action(self)


print("Cooperative chain:")
print("MRO:", " -> ".join(cls.__name__ for cls in Cooperative.__mro__))
Cooperative().action()

print("Explicit parent calls:")
ExplicitChild().action()

print("Inconsistent bases:")
class X:
    pass


class Y:
    pass


class XY(X, Y):
    pass


class YX(Y, X):
    pass


try:
    class Invalid(XY, YX):
        pass
except TypeError as error:
    print(f"TypeError: {error}")

This program ran on Python 3.11.16. I ran the named file and saw Cooperative, Left, Right, and Base print in sequence. The first three methods pass the call onward.

pankaj@askpython:~$ python3 multiple_inheritance_demo.py
Cooperative chain:
MRO: Cooperative -> Left -> Right -> Base -> object
Cooperative
Left
Right
Base
Explicit parent calls:
ExplicitChild
Left
Base
Right
Base
Inconsistent bases:
TypeError: Cannot create a consistent method resolution
order (MRO) for bases X, Y
Terminal output shows the MRO chain, repeated base call and inconsistent-order TypeError
The terminal capture shows this command’s cooperative, explicit-call, and error output.

Step 2: Read the MRO as the lookup route

The printed order is Cooperative, Left, Right, Base, and object. Python checks the class sequence for the requested name and uses the first definition it finds. It does not combine all matching method bodies automatically.

I checked Cooperative.__mro__ in the run and got Cooperative, Left, Right, Base, and object.

For quick inspection, compare these two forms:

  • Cooperative.__mro__ returns a tuple containing the stored class order.
  • Cooperative.mro() returns a list from the class’s MRO method.

Because super() follows the actual receiver’s MRO, Left.action() reaches Right in Cooperative but Base in a plain Left instance, as the Python super() reference explains.

Step 3: Compare super() with a named base call

ExplicitLeft and ExplicitRight each call Base.action(self) by name. I compared that path with Cooperative’s super() chain: Base printed twice for ExplicitChild, but once for Cooperative.

Without a super() call in a participating override, a cooperative chain stops there, so later bases are skipped without an MRO error.

Step 4: Inspect a rejected base order

XY places X before Y, while YX places Y before X. I defined Invalid(XY, YX), and Python returned “Cannot create a consistent method resolution order (MRO) for bases X, Y.” The class could not be created because no sequence can preserve both requested orders.

This failure happens while Python builds the class, before an instance or method call exists. Change the conflicting class relationships or base order.

Incompatible metaclasses or instance layouts can also prevent class creation, as described in this CPython documentation discussion.

Step 5: Coordinate base initializers

Python does not automatically call every base class’s __init__, so a derived initializer must arrange the calls it needs. In a cooperative design, each initializer should consume its named fields, pass remaining keywords through super() with compatible signatures, and leave no values for object.__init__ to reject, as the Python reference recommends.

Which Multiple Inheritance Edge Cases Cause Errors?

Separate a lookup result, a stopped method chain, and a class-creation failure because they need different checks.

CaseWhat happensNext check
Two bases define the same nameThe first matching definition in the MRO supplies the attribute.Inspect the order and decide whether that method should call super().
An override omits super()Later cooperative implementations are skipped. Python need not raise an error.Confirm that the method is meant to continue the chain.
Arguments do not fit a cooperative initializerA later method or object.__init__ can reject leftover values.Check which class consumes each argument and what gets forwarded.
Zero-argument super() is outside a method defined in a classThe call has no implicit class and first argument to use.Move it into a method defined in the class or supply valid explicit arguments.
Base ordering or layout constraints conflictPython cannot create the combined class.Review the bases, metaclasses, and instance layout requirements.

A mixin adds one focused behavior, and its small, documented contract should name any attributes it expects.

The Digital Cat’s mixin guide discusses this trade-off. A mixin fits when related class families need the same small capability, such as a logging method with a documented attribute contract. A formatter or repository object with its own state is different: pass it to a service through composition when it should be replaced independently or is not a kind of the service.

Ask whether the relationship is “is a” or “has a” before adding a base. A specialized parser can be a kind of parser, while a file reader owned by a service is a collaborator. Multiple inheritance should model a shared role, not just combine unrelated details to avoid duplication.

Conclusion

Read the MRO to see which definition wins, then use super() only when each participating method is intended to cooperate. A runnable trace makes both a shared-base handoff and an incompatible order visible before you extend the hierarchy.

For related topics, start with AskPython’s Inheritance in Python and Python Classes and Objects. Continue with Understanding the super() Method in Python or the official Python class tutorial.

FAQ

These answers cover syntax, method selection, and common questions about super().

Can a Python class inherit from multiple classes?

Yes. List two or more base classes in the class declaration, separated by commas. Python computes one MRO for the resulting hierarchy.

Which parent method does Python call first?

Python searches the class and then its MRO. The first class in that order that defines the requested name supplies it.

Does super() always call the direct parent?

No. It continues after the current class in the actual object’s MRO. In super(CurrentClass, self), CurrentClass is the class where the method is defined, not a chosen parent.

Can Python reject a multiple-inheritance class?

Yes. Python raises TypeError when it cannot build a consistent MRO for the requested base order. Some incompatible metaclass or instance-layout combinations also prevent class creation.

Is multiple inheritance the same as multilevel inheritance?

No. Multiple inheritance lists several direct bases. Multilevel inheritance means a class inherits from another derived class. A hierarchy can contain both shapes.

Does Python run every base __init__ automatically?

No. A derived initializer must arrange the base initialization it needs. A cooperative chain reaches another initializer only when each participating method calls super().

When should I use a mixin instead of composition?

Use a small mixin for one shared class capability. Prefer composition when the objects have separate state or lifecycles and do not need to be treated as one inheritance family.

Pankaj Kumar
Pankaj Kumar

I have been working on Python programming for more than 12 years. At AskPython, I share my learning on Python with other fellow developers.

Articles: 261