~/talk

Metaclasses Demystified

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

Covers what metaclasses are and how they actually change class creation showing concrete code patterns: implements a singleton metaclass that caches instances, uses __new__ to raise TypeError and enforce forbidden methods for compile‑time checks, overrides prepare for enum‑style attribute storage, mutates the MRO to append fallback behavior, and defines class dunder methods on the metaclass (ABCMeta usage included). Ends with a real incident where a metaclass solved test resource injection but a simpler non‑metaclass design proved preferable.

AI-written summary · about

  1. 0:00Introduction
  2. 2:06What are metaclasses
  3. 3:06Whats a class
  4. 5:23Metaclass magic
  5. 6:09What do metaclasses do
  6. 9:07Singletons
  7. 12:22Controlling Class Methods
  8. 14:29Class Name Space
  9. 16:07Method Resolution Order
  10. 18:27Class Dunder Methods
  11. 20:42Object Base Class
  12. 25:06Question
~/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.