~/talk

Supercharge your code with Python's 'match' statement

Talkat PyCon Italia 2024 · 2024-05-22..05-25· [python]
links:none on file
slides:none on file

Explains that Python’s match is structural pattern matching, not a fancy switch, and shows concrete rewrites: replace nested ifs and tuple unpacking with cases that capture values like ("ok", id) vs ("error", code) so the code becomes three concise cases; applies to dicts (GraphQL responses: errors vs data→hero→friends), lists, dataclasses and normal classes via the match protocol, and lets functions return different structures easily. Notes a bytecode speedup, a gotcha where bare names capture like variables, and the enum fix.

AI-written summary · about

  1. 0:00Introduction
  2. 1:06Python 3.10 match statement
  3. 3:59Structural pattern matching
  4. 10:15Tuple pattern matching demo
  5. 13:07API response handling
  6. 19:57Custom class pattern matching
  7. 23:55Matching different classes
  8. 27:56When to use match vs if-else
  9. 30:09Common match mistakes
  10. 33:43Designing functions with match
  11. 34:53Q&A session
~/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.