Introduction to Decorators: Power Up Your Python Code
summary
Covers how decorators actually work and how to write them: uses IPython, time.sleep, pathlib and random and standard tools like functools.cache and functools.wraps. Builds concrete decorators — a caching example around a slow_square, a before_and_after logger, a do_twice wrapper, a register-that-populates-a-global dict, and a retry decorator turned into a decorator-factory with retry with max_retries and per-decorator state stored as a function attribute — all shown running; notes history (introduced in Python 2.4, PEP 318).
AI-written summary · about
chapters (16)
- 0:00Introduction to decorators
- 4:06What is a decorator
- 14:50Functions as objects
- 26:52Dynamic function creation
- 33:57Function factories explained
- 44:19First decorator exercise
- 51:07Before-after decorator template
- 1:07:45Flexible decorator arguments
- 1:17:00Stacking decorators order
- 1:20:08Definition-time decorators
- 1:33:22Preserve metadata with wraps
- 1:39:44Register decorator tracking
- 1:45:09Retry decorator failures
- 1:58:35Decorators with parameters
- 2:07:37Stateful decorators
- 2:19:05Summary resources








