~/talk

Metaprogramming with Decorators, Metaclasses, and Dynamic Code Generation

Talkat PyCon US 2025 · 2025-05-16..05-18· [python]
links:none on file
slides:none on file

Covers concrete patterns and working code: a logger decorator that wraps functions, a class-based counter decorator that maintains call counts via __call__, a custom metaclass using type with __new__ and __init__ to enforce required attributes and log class creation, and an exec-generated function example that creates a square function at runtime. Demonstrates where these tools power Django, Flask, and FastAPI, shows the examples running, and warns about unsafe exec/eval with remedies like ast.literal_eval and restricted namespaces.

AI-written summary · about

  1. 0:00Metaprogramming in Python
  2. 3:39Python metaprogramming
  3. 9:24Function decorators
  4. 14:01Class decorators
  5. 16:53Decorators in frameworks
  6. 17:14Metaclasses in Python
  7. 21:30Custom metaclasses
  8. 24:19Metaclasses enforcing contracts
  9. 26:28Dynamic code generation
  10. 27:50Metaprogramming security
~/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.