mypy Basics (Practical Workflow)
On this page
mypy as a Safety Net
mypy catches mismatches before runtime. The best ROI is at boundaries and shared libraries.
Incremental Adoption
- Start with new code and public modules.
- Annotate functions that form contracts (APIs, adapters, utils).
- Tighten rules gradually.
Common mypy Workflow
# Run mypy on a package mypy myapp # Typical target: module boundaries and shared libs first
Operational Checklist
- Fail CI on mypy errors for enforced modules.
- Avoid blanket
Any; use it only as a temporary escape hatch. - Keep type ignores localized and documented.
Failure Modes
- All-or-nothing adoption: teams abandon it due to initial noise.
- Ignore sprawl: widespread
# type: ignoredefeats the purpose.