super() is Python’s built-in function for accessing methods and attributes from a superclass — enabling clean, cooperative multiple inheritance and method overriding without hardcoding parent class names. In 2026, super() remains the recommended way to call parent methods in subclasses, especially in complex hierarchies, data science base classes (custom pandas/Polars/Dask extensions), and modern frameworks (FastAPI dependencies, SQLAlchemy models, dataclasses) — supporting zero-argument form (Python 3 style) for simplicity and MRO-aware resolution.
Here’s a complete, practical guide to using super() in Python: zero-arg vs explicit form, cooperative inheritance, real-world patterns (earthquake event hierarchy, mixin validation, super in multiple inheritance), and modern best practices with type hints, MRO inspection, performance, and integration with dataclasses/Pydantic/Polars/Dask.
Zero-argument super() — modern, clean, Python 3 preferred form.
class BaseEvent:
def __init__(self, mag):
self.mag = mag
def describe(self):
return f"Mag {self.mag:.1f}"
class QuakeEvent(BaseEvent):
def __init__(self, mag, place):
super().__init__(mag) # calls BaseEvent.__init__
self.place = place
def describe(self):
parent_desc = super().describe() # calls BaseEvent.describe
return f"{parent_desc} at {self.place}"
eq = QuakeEvent(7.2, "Japan")
print(eq.describe()) # Mag 7.2 at Japan
Explicit super(SubClass, instance_or_class) — legacy or special cases.
class AdvancedQuake(QuakeEvent):
def __init__(self, mag, place, depth):
super(AdvancedQuake, self).__init__(mag, place) # explicit
self.depth = depth
# Class-level super (for class methods)
class Config:
DEFAULT_MAG = 0.0
@classmethod
def from_dict(cls, data):
obj = super(Config, cls).__new__(cls) # explicit for __new__
obj.__dict__.update(data)
return obj
Real-world pattern: cooperative inheritance in earthquake event hierarchy — multiple bases & mixins.
class TimestampMixin:
def __init__(self, time, **kwargs):
self.time = time
super().__init__(**kwargs)
def describe(self):
return f"{super().describe()} on {self.time.date()}"
class LocationMixin:
def __init__(self, place, **kwargs):
self.place = place
super().__init__(**kwargs)
def describe(self):
return f"{super().describe()} at {self.place}"
class FullQuake(TimestampMixin, LocationMixin, BaseEvent):
def __init__(self, mag, place, time):
super().__init__(mag=mag, place=place, time=time)
def describe(self):
return super().describe() # calls TimestampMixin.describe ? LocationMixin.describe ? BaseEvent.describe
event = FullQuake(7.5, "Alaska", pd.Timestamp("2025-03-01"))
print(event.describe())
# Mag 7.5 at Alaska on 2025-03-01
Best practices for super() in Python & data workflows. Prefer zero-argument super() — inside methods (Python 3+): super().method() — clean & MRO-safe. Modern tip: use Polars/Dask — super() in custom DataFrame subclasses for extension. Use super() in __init__ — always call parent init first. Add type hints — class QuakeEvent(BaseEvent): def describe(self) -> str: .... Use super() in multiple inheritance — follow MRO (method resolution order). Use super().__init__() — in all subclasses unless intentionally skipping. Use super() in classmethods — super().__new__(cls) for factories. Use super() in properties — @property def value(self): return super().value + 1. Use super() in mixins — cooperative design (call super even if no parent). Avoid explicit super(Child, self) — fragile in multiple inheritance. Use cls.__mro__ — inspect method resolution order. Use super() with @classmethod — for alternative constructors. Use super() in ABCs — call abstract methods safely. Use super() in dataclasses — super().__init__(**kwargs). Use super() in Pydantic — base model extensions. Use super() in decorators — method wrapping. Use super() in metaclasses — class creation hooks. Profile performance — super() is fast; negligible overhead.
super() accesses superclass methods/attributes — zero-arg form is clean and MRO-safe, enabling cooperative inheritance and method chaining. In 2026, use zero-arg super() everywhere, in __init__, properties, classmethods, and integrate with dataclasses/Pydantic/Polars/Dask for extensible classes. Master super(), and you’ll build robust, inheritance-friendly, and maintainable class hierarchies in any Python project.
Next time you need to call a parent method — use super(). It’s Python’s cleanest way to say: “Let the superclass do its part — then I’ll add mine.”