Track 12 · Lesson 6 of 12
Decorators in depth
Keep function metadata with functools.wraps, write decorators that take arguments, stack them in the right order and cache results with lru_cache.
You will be able to
- Preserve a decorated function's name and docstring with functools.wraps
- Write a decorator factory that takes arguments, such as @retry(times=3)
- Predict the order in which stacked decorators wrap and run
- Speed up repeated pure computations with functools.lru_cache and cache, and know when caching is wrong
Included with a Formula Quest membership
It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.
View Formula Quest memberships
Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.