~/talk

Having fun with pydantic and pattern matching

Talkat PyCon US 2024 · 2024-05-15..05-23· [python]
links:none on file
slides:none on file

Asserts that match‑case (Python 3.10) is less necessary once messages are validated into typed models and routed, and builds an event consumer that reads endless JSON messages (Kafka/Rabbit style), validates them into pydantic models for account_created/account_updated/account_deleted, and dispatches handlers. Replaces many match cases with a pydantic TypeAdapter for Union models and then uses functools.singledispatch to register handlers. Malformed messages raise validation errors until union includes Any; solution works and is easy to extend though no performance benchmarks are shown.

AI-written summary · about

  1. 0:00Introduction
  2. 1:04Python’s match-case statement
  3. 4:15Ordering in match-case patterns
  4. 5:39Event stream consumption case study
  5. 8:56Refactoring with match-case
  6. 14:22Untyped dictionaries problem
  7. 15:24Pydantic models for validation
  8. 17:34Pydantic with match-case
  9. 18:37Pydantic unions vs match-case
  10. 21:04Handling malformed data
  11. 22:09Specialized types for matching
  12. 23:13functools singledispatch
  13. 24:41Open-closed event handling
  14. 25:44Pattern matching power summary
  15. 27:51Q&A
~/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.