Lesson 4: Type hints and dataclasses, saying what each value is
18 min read·14 Oct 2026
Module 9 · Lesson 4 · About 50 minutes · Needs: Module 9 Lessons 1 to 3 (classes,__init__,__repr__,__eq__), Module 6 Lesson 2 (the mutable default trap), Module 7 Lesson 4 (%pip)
The situation
Tom is reading your code on the café laptop. "This late_fee takes days_late. Is that a number? Could it be the text from the spreadsheet? And every class starts with an __init__ that only copies values onto self."
Both are fair. This lesson fixes them: type hints say what each value is, and dataclasses write the repetitive parts of a class for you. Jonah's loan L04, Frankenstein, 16 days late and 300 pence owed today, runs through the whole lesson.