MODULE 07 · INTERMEDIATE

Type Hints and Modern PythonPython · Module 7

Describe contracts with annotations, check them with mypy, and use dataclasses and protocols to make data-heavy code easier to change.

3 lessons12 min readingBuild reliable programs1 project
Free, self-paced, and open to everyone. No account needed.
WHAT THIS MODULE COVERS

Type Hints and Modern Python

Describe contracts with annotations, check them with mypy, and use dataclasses and protocols to make data-heavy code easier to change.

BEFORE YOU START

Functions, classes, and basic Python syntax.

WHAT YOU’LL BE ABLE TO DO

Add type hints to functions and classes, use mypy for static type checking, and apply dataclasses for clean data models with type safety.

THE LESSON SEQUENCE

Read in order, or jump to what you need.

Every lesson builds on the one before it. Open any lesson to read the explanation, run the examples, and try the practice challenges.

  1. 07.01
    Introduction to Type Hints

    Add annotations that document real contracts, run a static checker, and model records with dataclasses.

    4 min
  2. 07.02
    Advanced Type Hints

    Use generics, protocols, literals, and strict checking to describe behavior that ordinary annotations cannot capture.

    4 min
  3. 07.03
    Project: A Typed Data Model LibraryProject

    Build a small order library with frozen dataclasses, exact money, a Protocol discount boundary, and a green mypy --strict run.

    4 min
MODULE SELF-CHECK

Ready to move on?

Add type hints to a module, run mypy in strict mode, and fix all type errors without changing runtime behavior.

Open the module self-check