Introduction to Decorators: Power UP Your Python Code
summary
The session shows concrete code not handwavy theory: it demos functools.lru_cache to cache a slow square, builds a before_and_after decorator, a do_twice decorator that returns a two‑tuple of results, and a register decorator that stores functions in a dict. It implements a retry decorator (including a max‑retries example) and then a class‑based decorator that keeps retry counts across calls, uses functools.wraps / update_wrapper to preserve metadata, and points to tenacity as a production retry library.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 2:25What are decorators
- 9:03Functions are first class objects
- 13:25Function references
- 15:49Function factories
- 19:59Decorators
- 26:22Reverse Factory
- 29:52Exercise
- 35:37Solution
- 39:32Unpacking of Lists
- 47:12Exercise 2 Return Values
- 50:37Exercise 3 Stack Reader
- 55:47Defining Decorators
related talks
02h 21mIntroduction to Decorators: Power Up Your Python Code
03h 21mIntroduction to Decorators: Power Up Your Python Code
02h 15mAll about decorators
29mHow Decorators Function
29mOn the Use and Misuse of Decorators
01mDecorators Demystified
01mTutorial Sneak Peak: "All about decorators"
19mDecorators for Data Science
