Tracing Nested Calls with a Decorator

medium
Unit 14 · Parsing & Decorators0/3 to milestone

Write a decorator factory trace(log) where log is a list that receives lines. Each traced call appends:

  • on entry: "{indent}→ name(args)", with arguments formatted with repr (positional first, then key=value), comma-separated
  • on return: "{indent}← name = result" (using repr)
  • if it raises: "{indent}✗ name raised ExceptionName", then re-raise
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Tracing Nested Calls with a Decorator · TechGradify