Please Don't Put That in a Dict: Better Data Models in Python
summary
A hiking-recommendation app built from dictionaries silently suggests closed trails when a field rename turns "status" into None, proving that shape notes fail in prod. The concrete path is: use TypedDict to document shapes for early checks, prefer data class post_init for construction-time checks when appropriate, and use Pydantic at the door to parse don't validate so incoming JSON and LLM outputs are rejected or coerced before anything trusts them.
AI-written summary · about
chapters (11)
- 0:00Introduction
- 1:30Hobby app to dict disaster
- 5:46What went wrong
- 7:10Python data model options
- 9:39When to use dataclass
- 13:58Type hints aren't enough
- 16:29Parse at the door with Pydantic
- 19:38Merging feeds with validation
- 21:03Fixing trip report schema
- 24:15Dict needs a model
- 25:45Closing remarks
related talks
26mIntro to Pydantic, run-time type checking for your dataclasses
24mPython for Humans, Designing Python Code Like a User Interface
30mPython for Humans - Designing Python Code Like a User Interface
27m"How to Use Static Typing in Python with Type Hints, MyPy and Pydantic"
35mStatic Typing in Python
28mMind the gap! Why static typing requires more than just adding annotations
24m"A Confession of My Python Sins"
31mStatic Type Analysis for Robust Data Products
