~/talk

Introduction to Decorators: Power UP Your Python Code

Talkat PyCon US 2021 · 2021-05-14..05-15· [python, developer-experience]
links:none on file
slides:none on file

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

  1. 0:00Introduction
  2. 2:25What are decorators
  3. 9:03Functions are first class objects
  4. 13:25Function references
  5. 15:49Function factories
  6. 19:59Decorators
  7. 26:22Reverse Factory
  8. 29:52Exercise
  9. 35:37Solution
  10. 39:32Unpacking of Lists
  11. 47:12Exercise 2 Return Values
  12. 50:37Exercise 3 Stack Reader
  13. 55:47Defining Decorators
~/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.