~/talk

The Zen of Polymorphism: Choosing between isinstance(), methods, and @singledispatch

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

Compares three concrete implementations on a calculator AST: naive type switches with isinstance(), methods on classes, and functools.singledispatch; claims singledispatch gives late registration and decoupling while avoiding duplication, then shows a catamorphism (visitor) that factors traversal from operations so pretty‑print, eval, complexity, and type checks reuse the same walk. Builds a working calculator and a tiny custom dispatcher that uses the class MRO and shows the approaches trade performance for maintainability.

AI-written summary · about

  1. 0:00Introduction
  2. 1:09Calculator scenario
  3. 2:33isinstance approach
  4. 7:27Object-oriented programming approach
  5. 15:15Dynamic dispatch with functools.singledispatch
  6. 26:03Catamorphism
  7. 37:53Choosing technique
  8. 38:57Conclusion
~/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.