super()
Cooperative multiple inheritance — call the parent's method without hard-coding the class name.
Demo
super() is a proxy for the NEXT class in the MRO (method resolution order). The demo shows three common scenarios. INIT: subclass __init__ calls super().__init__() to run parent initialization. SINGLE: an override calls super().method() to extend the parent's behavior. DIAMOND: with multiple inheritance, super() follows the linearized MRO — critical for cooperative multiple inheritance.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| type | type | no (__class__) | The starting class for MRO lookup. In the zero-arg form (Python 3.0+), the compiler fills this in as the class the method is defined in. |
| obj_or_type | Any | no (self) | The instance (or class) whose MRO to walk. The zero-arg form uses the first positional argument of the enclosing method. |
Return value
super — A proxy object. Calling methods on it dispatches to the parent (next-in-MRO) class, bound to the current instance or class. `super()` inside a method (Python 3.0+) is equivalent to `super(__class__, self)` — the compiler fills in the arguments.
Common patterns
class Employee(Person): def __init__(self, name, salary): super().__init__(name) self.salary = salary
class Loud(Talker): def speak(self): text = super().speak() return text.upper()
class A: def do(self): print("A"); class B(A): def do(self): print("B"); super().do() class C(A): def do(self): print("C"); super().do() class D(B, C): def do(self): print("D"); super().do()
super(Employee, e).__init__(name)
Examples
Pitfalls
# at module level super()
super(SomeClass, instance)
# in D(B, C): # super() in B goes to A, right?
D.__mro__
class B(A): def do(self): print("B") # no super() — stops here
class B(A): def do(self): print("B") super().do()
class D(B, C): def do(self): B.do(self) # C.do never runs
class D(B, C): def do(self): super().do()
When to use
- Every __init__ in a subclass — the standard convention
- Extending any inherited method rather than replacing it
- Cooperative multiple inheritance and mixins
- When a subclass wants to add behavior around a parent method
- Complete replacement of a parent method — do not call super()
- Naming ambiguity — if the parent method is unclear, refactor
- Deep hierarchies — often a sign that composition would be clearer
- When you truly want a specific class's method regardless of MRO — use ParentClass.method(self)
Notes
FAQ
If the parent has meaningful __init__ behavior, yes — otherwise inherited attributes will not initialize. The one exception: if you inherit directly from object and have no other cooperative parents, super().__init__() with no args is a no-op but still recommended for consistency.