Enforce Static type checking on CI
What
This pull request introduces several improvements and refactorings across the codebase, with a focus on type safety, static type checking, and code clarity. The most significant changes include the addition of static type checks to the test workflow, enhanced type annotations throughout the Python code, and interface updates for email clients. Below is a summary of the most important changes grouped by theme.
Why
These changes collectively improve the codebase's maintainability, reliability, and readiness for static analysis.
Ticket
https://trello.com/c/52qyrWvq/1509-enforce-type-checking-at-ci-stage
Should also consider not type checking files in app/migrations. We exclude them from other static analysis:
https://github.com/alphagov/notifications-api/blob/e5ec819200270c43d8fb1f0e2c4882cc36d6564d/ruff.toml#L7
I am running this branch on my computer, and make test is failing because of missing stubs ([import-untyped]) and an attribute error ([attr-defined]). You can also see these errors in the pipeline.
You will probably need to fix the stub errors by running mypy --install-types in the make bootstrap command, and handle the attribute errors in the mypy.ini file.