~/talk

Introduction to Decorators: Power Up Your Python Code

Talkat PyCon US 2023 · 2023-04-19..04-27· [python, developer-experience]
links:none on file
slides:none on file

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

  1. 0:00Introduction to decorators
  2. 4:06What is a decorator
  3. 14:50Functions as objects
  4. 26:52Dynamic function creation
  5. 33:57Function factories explained
  6. 44:19First decorator exercise
  7. 51:07Before-after decorator template
  8. 1:07:45Flexible decorator arguments
  9. 1:17:00Stacking decorators order
  10. 1:20:08Definition-time decorators
  11. 1:33:22Preserve metadata with wraps
  12. 1:39:44Register decorator tracking
  13. 1:45:09Retry decorator failures
  14. 1:58:35Decorators with parameters
  15. 2:07:37Stateful decorators
  16. 2:19:05Summary resources
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.