Main Ecosystems
HomePython CorePandas ReferenceNumPy ScientificFastAPI & PydanticDjango Enterprise
More Ecosystems
Environment & SetupRequests & HTTPAsyncIO ConcurrencyObject-Oriented OOPPyTorch Deep LearningScikit-Learn MLFlask FrameworkWeb ScrapingDatabase & ORMDevOps & Docker

TypeError: __init__() missing required positional arguments in Inheritance Chain

Verified FixPython 3.10+Python Native OOPSilo: oop

Quick Fix / Solution Rapide

Forward all required parent constructor parameters in super().__init__(arg1, arg2) or use *args, **kwargs cooperative propagation.

Root Cause Analysis

This error occurs when a child class defines its own __init__() constructor and invokes super().__init__(), but omits one or more mandatory positional arguments required by the parent class's __init__() signature.

1. Forgetting Parent Parameters in super().init()

If Base defines def __init__(self, name, id):, a derived class Child calling super().__init__() with no arguments fails with TypeError: Base.__init__() missing 2 required positional arguments: 'name' and 'id'.

2. Inconsistent Keyword Argument Propagation in Cooperative Inheritance

In multiple inheritance chains where classes use super().__init__(**kwargs), forgetting **kwargs in an intermediate class strips parameters destined for classes higher in the MRO.

3. Subclassing Framework Base Classes (FastAPI, Django, PyTorch)

Subclassing torch.nn.Module or django.forms.Form and overriding __init__ without calling super().__init__(*args, **kwargs).

4. Adding Required Arguments in Parent Class Refactoring

Adding a new mandatory parameter to a core base class without updating all existing subclasses across the codebase.

Reproduction Code (MCVE)

Example: Bug Reproduction
class BaseEntity:
    def __init__(self, entity_id, created_at):
        self.entity_id = entity_id
        self.created_at = created_at

class UserEntity(BaseEntity):
    def __init__(self, username):
        self.username = username
        # Bug: missing entity_id and created_at arguments
        super().__init__()

UserEntity('alice')

Solution 1: Explicitly Pass Required Arguments to super().__init__()

Accept parent arguments in the child constructor and pass them directly to super().__init__().

Example: Recommended Solution
class BaseEntity:
    def __init__(self, entity_id, created_at):
        self.entity_id = entity_id
        self.created_at = created_at

class UserEntity(BaseEntity):
    def __init__(self, entity_id, created_at, username):
        super().__init__(entity_id, created_at)  # Explicit parameter forwarding
        self.username = username

user = UserEntity(101, '2026-01-01', 'alice')
print(f'User initialized: id={user.entity_id}, name={user.username}')

Solution 2: Use *args and **kwargs for Resilient Propagation

Use *args, **kwargs to decouple child constructors from changes in parent constructor signatures.

Example: Alternative Solution
class BaseEntity:
    def __init__(self, entity_id, created_at, **kwargs):
        super().__init__(**kwargs)
        self.entity_id = entity_id
        self.created_at = created_at

class UserEntity(BaseEntity):
    def __init__(self, username, **kwargs):
        super().__init__(**kwargs)
        self.username = username

user = UserEntity(username='alice', entity_id=101, created_at='2026-01-01')
print(f'User via kwargs: {user.username}, {user.entity_id}')

A common mistake is placing required positional arguments after default arguments in __init__ signatures (e.g. def __init__(self, name='default', id):). Python syntax requires non-default arguments to precede default arguments. Edge cases occur with PyTorch modules: torch.nn.Module.__init__() takes no arguments; always call super().__init__() with zero arguments for PyTorch models. Contrast this error with TypeError: __init__() takes 2 positional arguments but 3 were given, which occurs when too many arguments are passed.