-
Notifications
You must be signed in to change notification settings - Fork 83
Description
Why?
Helps catch bugs/unhandled cases and makes IDE completions a lot more useful.
With the newly-typed models (#1849) we're now in a good place to start threading types more completely everywhere else.
How?
We already run mypy in CI, but the defaults are quite liberal - for instance it doesn't check functions without a type signature at all.
We can progressively opt modules can be gradually opted in to the stricter checks. The ideal goal would be to be able to run with mypy --strict but this will either require a lot of our 3rd party dependencies to have typing added, or lots of type ignore comments. So it's perhaps not worth fixating on. https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options has a list of options that --strict turns on.
As a pragmatic goal to get a bunch of the benefit, I'd suggest we aim for:
-
disallow_incomplete_defs- errors on partially-typed definitions (probably easiest to start with) -
disallow_untyped_calls- errors when we call untyped code from typed code -
check_untyped_defs- perhaps worth doing globally, but if doing per module probably beter to go straight for... -
disallow_untyped_defs(the big one) - enforces that all our code has complete type hints on it.
Any new stuff we add should have these turned on, and we can gradually migrate other modules to it.
Tracking progress
Mypy now generates a report for type coverage when it runs in gh actions. You can see it on the "Test" workflow's summary.
According to mypy, as of 83941c7 we are 46.50% imprecise (https://github.com/emfcamp/Website/actions/runs/17533213709)