Everything you need to know but were afraid to ask about Data Classes
summary
Dataclasses provide a mutable, named‑tuple–like class that auto-generated __init__/__repr__/__eq__ saves lots of boilerplate, can be frozen for immutability, and supports optional type annotations (not enforced at runtime). They derive design and tradeoffs from attrs, offer a backport to 3.6, and a Damla Altun tool reveals the actual generated code. Watch for inheritance overwriting base fields, optional __slots__ for memory savings, and a real example: Pursued PyBear uses dataclasses for its event system and it works in practice.
AI-written summary · about
chapters (11)
- 0:00Intro
- 2:13Unwrapping the story
- 4:44Context
- 5:10Dot Notation
- 6:05Outers Project
- 7:29Dunder
- 9:46Wallet
- 13:56Data Classes
- 19:16Inheritance
- 21:31State Objects
- 24:24Type annotations
related talks
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
33mData Class Serialization The Right Way
29mMaking Data Classes Work for You
47mA Deep-Dive Into Python Classes
01h 10mIt's Pythons All The Way Down: Python Types & Metaclasses Made Simple
30mThe Wizardry of Metaprogramming
