The Python Substrate
The data model and dunder methods, dataclasses and value semantics, Protocol and structural typing with mypy, context managers, and proving a design works with pytest, pytest-mock, and mypy.
The data model: dunder methods as the substrate
Operators, builtins and f-strings are calls on the type, shown on shipping values whose equality, arithmetic, ordering, containers and text each fail somewhere distant when a method is missing or wrong.
Dataclasses and value semantics
One frozen, slotted dataclass declaration writes the structure of the Value Object pattern, and three decisions stay with the author: the invariant, immutable field types, and value or entity.
Protocol, duck typing, and structural typing with mypy
An interface in Python is a shape the checker compares where a value is used, absence is a member of that shape's type so Null Object dissolves into an optional return, and Protocol and ABC are two mechanisms behind one word.
Context managers: deterministic cleanup
The with statement runs __exit__ on every path out of a block, which removes the boilerplate of Resource Acquisition; what release means, whether an exception propagates and the order across resources stay with the author.
Proving it works: pytest, pytest-mock, and mypy
A test is evidence for one named claim, and it counts once it has been seen to fail. Fixtures supply dependencies by name, a mock checks less than a fake, create_autospec checks call shapes, and mypy checks the tests too.