Making Data Classes Work for You
summary
Starts from a concrete problem (an int constrained to 1–10) and shows code that enforces validity by building a small immutable type OneToTen using dataclasses with frozen=True and validation in __post_init__. Shows composition into Person made from FullName BirthDate EmailAddress, uses enums for months, checks ranges (days 1–31, years 1900–2022), and demonstrates the resulting types are usable and prevent invalid states.
AI-written summary · about
chapters (8)
- 0:00Introduction
- 1:07Checking for errors
- 4:20Encapsulation
- 6:48Data Classes
- 9:08Replace Function
- 10:29Frozen Objects
- 16:08Composing
- 18:57enums
related talks
26mEverything you need to know but were afraid to ask about Data Classes
45mDataclasses: The code generator to end all code generators
32mEasier Classes: Python Classes Without All the Cruft
22mEasier Classes: Python Classes Without All The Cruft
28m"Validating Complex Types Using Pydantic"
33mElegant Solutions For Everyday Python Problems
26mIntro to Pydantic, run-time type checking for your dataclasses
27mUnder the Hood Hacking Python Data Types for Fun and Power
