Counting and Timing Calls with a Decorator

easy
Unit 10 · Collections0/3 to milestone

Write a decorator instrument that records, on the wrapper:

  • calls: how many times the function was called
  • errors: how many calls raised an exception (the exception must still propagate)
  • last_args: the (args, kwargs) of the most recent call

Use functools.wraps so the wrapped function keeps its __name__.

#decorators#functools2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Counting and Timing Calls with a Decorator · TechGradify