~/talk

Dipping my toes in metaprogramming

Talkat PyCon Italia 2025 · 2025-05-28..05-31· [compilers-and-language-design]
slides:none on file

Shows how Python's __new__ returns arbitrary objects and how it differs from __init__; implements a Number class whose __new__ swaps cls for OddNumber or EvenNumber so instantiating Number(3) yields an OddNumber, and reproduces pathlib's OS-based Path swap for Windows/POSIX via cls replacement. Demonstrates printing inside __new__ to prove it runs, uses super().__new__(cls, ...) to allocate the object, builds a tolerant float subclass that must use __new__ because floats are immutable, and all live demos work.

AI-written summary · about

  1. 0:00Introduction and motivation
  2. 3:18Emulating path with numbers
  3. 10:33Understanding __new__ method
  4. 16:18Dynamic class switching
  5. 20:34Path implementation details
  6. 27:24Immutability and floats
  7. 31:41Meta classes and conclusion
~/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.