Typing, Dataclasses, and Code Structure¶
Under development
This lesson is part of the course scaffold and is being actively written. The learning objectives and outline below define its final scope.
Learning objectives¶
By the end of this lesson you will be able to:
- Annotate research code with type hints (including generics,
Optional, andProtocol) and validate it under a strict mypy configuration. - Model domain objects such as bars, orders, and instruments as frozen dataclasses with enums for categorical fields.
- Refactor a notebook-style script into a structured package with clear module boundaries and a testable public interface.
- Configure mypy in a project and interpret its errors well enough to fix them rather than silence them.
Outline¶
- Type hints — annotations, generics, Optional/Union, Protocols for duck typing
- Dataclasses — frozen instances, defaults, ordering, slots, when to reach for them
- Enums — order sides, instrument types, venue codes as typed constants
- Structuring research code — package layout, notebooks vs modules, import discipline
- mypy in practice — configuration, strictness levels, common error patterns
- Refactoring case study — from a 400-line script to a small package