Lesson 2: Decorators: wrapping a function without changing it
16 min read·14 Oct 2026
Module 10 · Lesson 2 · About 45 minutes · Needs: Module 6 Lesson 3 (functions as values, nested functions,nonlocal), Module 6 Lesson 2 (*args,**kwargs), Module 7 (thebooknookpackage)
The situation
Amira's request for this module is "Make sure it never breaks." Before anything can be tested, she wants to see what the shelf's code is doing. When a fee looks wrong, she asks: which function was called, with what, and what did it answer?
A print inside every rule would clutter it. This lesson adds the note from outside, with a decorator: a function that wraps another function and adds work around it. You will follow Ben's L13, 9 days late, which must still cost 180 pence.