Novaverse Chronicles₉
We trace Python’s super() in real time — from child to parent and back — using a SecureLogger experiment, live prints, and a multi-level inheritance demo.
Chapter Eight — Lesson 03.1: Inside super() — The SecureLogger Experiment
We’ll watch super() jump up the inheritance chain and return, with a live print trace and a tiny multi-level demo.
From: Lesson 03 — OOP Basics: The Architecture of Objects •
Next: Lesson 04 — File I/O + Logging (coming soon)Nova: Teslanic, I get what super() does, but I want to see it move.
Teslanic: Then we’ll trace it. We’ll build a secure logger, call super(), and watch control jump to the parent and bounce back.
1) Base Example — Logger → SecureLogger
The child calls the parent, extends the message, and returns a richer result.
class Logger:
def log(self, message):
return f"[LOG] {message}"
class SecureLogger(Logger):
def log(self, message):
base = super().log(message) # calls Logger.log
return f"{base} [ENCRYPTED]"
l = Logger()
sl = SecureLogger()
2) Live Trace — See the Jump and Return
Let’s print markers to see the exact execution order — no guessing.
class Logger:
def log(self, message):
print("➡️ Enter Logger.log")
result = f"[LOG] {message}"
print("⬅️ Exit Logger.log with:", result)
return result
class SecureLogger(Logger):
def log(self, message):
print("➡️ Enter SecureLogger.log")
base = super().log(message) # jump up to Logger.log
print("↩️ Back in SecureLogger.log with:", base)
result = f"{base} [ENCRYPTED]"
print("⬅️ Exit SecureLogger.log with:", result)
return result
SecureLogger().log("System started")
Expected Output
➡️ Enter SecureLogger.log
➡️ Enter Logger.log
⬅️ Exit Logger.log with: [LOG] System started
↩️ Back in SecureLogger.log with: [LOG] System started
⬅️ Exit SecureLogger.log with: [LOG] System started [ENCRYPTED]
🏁 Final returned value: [LOG] System started [ENCRYPTED]
Read it like a relay:
child starts → jumps to parent → parent returns → child resumes and finishes.
3) What’s Happening — The “Trampoline” Diagram
Start: SecureLogger.log("System started")
- No magic:
super()uses the class's MRO (method resolution order) to locate the parent method. - Control returns: after the parent finishes, execution continues right after the
super()call. - Benefit: no duplication — just behavior extension.
4) Multi-Level Demo — Grandmother → Mother → Child
Each level cooperates by calling super(). The final result is built layer by layer.
class Grandmother:
def log(self, message):
return f"[GRANDMA] {message}"
class Logger(Grandmother):
def log(self, message):
base = super().log(message) # Grandmother.log
return f"{base} -> [MOTHER] {message}"
class SecureLogger(Logger):
def log(self, message):
base = super().log(message) # Logger.log
return f"{base} -> [CHILD] {message}"
sl = SecureLogger()
print(sl.log("System started"))
Pattern:
Each class adds its part, then calls upward. When the top returns, control flows downward again, composing the final result.
Nova: So super() isn’t a teleport — it’s a polite handoff and a clean return.
Teslanic: Exactly. Cooperative inheritance.
Now we’re ready to teach objects to remember — files and logs next.
Checkpoint — Lock These In
super()calls the parent method found by the MRO.- Execution returns to the child right after the
super()call. - Use it to extend behavior — not to duplicate parent code.
Back to: Lesson 03 — OOP Basics: The Architecture of Objects
Up next: Lesson 04 — File I/O + Logging (coming soon)
Note
If you find any part of this post unclear or technically inaccurate, I would appreciate hearing from you. Improving the precision of these explanations is an ongoing process, and your feedback helps strengthen the material.