Python
Multiple Inheritance
Object-Oriented Programming
Init Method
Programming Best Practices

Calling parent class __init__ with multiple inheritance, what's the right way?

Object-Oriented Design practice on Codemia

Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.

Practice OOD

Introduction

In Python multiple inheritance, the right way to call parent __init__ methods is usually not to name each parent explicitly. The preferred approach is cooperative initialization with super(), where every class in the hierarchy participates and forwards unused arguments so Python's method resolution order can initialize each base exactly once.

Why Explicit Base Calls Go Wrong

A tempting first draft looks like this:

python
1class A:
2    def __init__(self):
3        print("A")
4
5class B(A):
6    def __init__(self):
7        A.__init__(self)
8        print("B")
9
10class C(A):
11    def __init__(self):
12        A.__init__(self)
13        print("C")
14
15class D(B, C):
16    def __init__(self):
17        B.__init__(self)
18        C.__init__(self)
19        print("D")

This is fragile because A.__init__ can run more than once. That is exactly the kind of diamond-shaped problem Python's method resolution order is designed to solve.

Use Cooperative super()

The correct pattern is to let each class call super().__init__() and trust the MRO to visit each class once in the right order.

python
1class A:
2    def __init__(self, **kwargs):
3        super().__init__(**kwargs)
4        print("A")
5
6class B(A):
7    def __init__(self, **kwargs):
8        super().__init__(**kwargs)
9        print("B")
10
11class C(A):
12    def __init__(self, **kwargs):
13        super().__init__(**kwargs)
14        print("C")
15
16class D(B, C):
17    def __init__(self, **kwargs):
18        super().__init__(**kwargs)
19        print("D")
20
21
22D()
23print(D.mro())

With cooperative inheritance, A is initialized once, and the order follows Python's MRO rather than your manual guesswork.

Forward Arguments with **kwargs

Real constructors usually take parameters, so cooperative initialization needs a way to pass arguments along without every class knowing every other class's needs.

python
1class Timestamped:
2    def __init__(self, created_at=None, **kwargs):
3        super().__init__(**kwargs)
4        self.created_at = created_at
5
6class Named:
7    def __init__(self, name, **kwargs):
8        super().__init__(**kwargs)
9        self.name = name
10
11class User(Named, Timestamped):
12    def __init__(self, name, created_at=None, **kwargs):
13        super().__init__(name=name, created_at=created_at, **kwargs)
14
15
16user = User(name="Ava", created_at="2025-09-23")
17print(user.name, user.created_at)

This is the core cooperative pattern:

  • accept the arguments your class owns
  • pass the rest through with **kwargs
  • call super()

That way, each class handles only its own state while still participating in the shared initialization chain.

MRO Is the Contract

Python determines the call order using the method resolution order. You can inspect it with Class.mro().

python
print(User.mro())

Understanding the MRO matters because super() does not mean "call my parent class directly." It means "continue to the next class in the MRO." That is why the same super() call can behave differently depending on the full inheritance graph.

When Multiple Inheritance Is the Wrong Tool

Sometimes the best answer is not a better __init__ pattern but a simpler design. If the classes are not intentionally cooperative, forcing them into multiple inheritance can create confusing argument flow and fragile constructors.

Composition is often easier to reason about when:

  • the classes were not designed to cooperate with super()
  • constructor arguments overlap awkwardly
  • only behavior reuse is needed, not a shared type hierarchy

Multiple inheritance is powerful, but it works best when the participating classes are written to support it.

Common Pitfalls

The biggest mistake is mixing explicit base-class calls with super() in the same hierarchy. That usually produces duplicate initialization or skipped classes.

Another is forgetting to forward **kwargs. If one class consumes its own argument and then drops the rest, the cooperative chain breaks.

Developers also sometimes assume super() means "call my immediate parent." In Python multiple inheritance, it really means "follow the next step in the MRO."

Finally, if one third-party base class does not cooperate with super(), the clean cooperative pattern may not be available. In that case, you need a more careful design decision instead of blindly copying a multiple-inheritance recipe.

Summary

  • In Python multiple inheritance, prefer cooperative initialization with super().
  • Let every participating class call super().__init__() exactly once.
  • Use **kwargs to pass unused constructor arguments through the chain.
  • Rely on the MRO instead of manually naming each base class.
  • If the classes are not designed to cooperate, composition may be a better design than multiple inheritance.

Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Object-Oriented Design practice on Codemia

Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.

Practice OOD