Add basic support for typechecking
Static typechecking can help make IDEs and editors smarter, uncover hidden bugs, and may help people read and understand the code better.
This merge request:
-
enables static typechecking via
mypy
(see also extra/mypy); -
fixes a couple of typing issues, which would interfere with type checking;
-
adds a CI step that will fail when a commit introduces typing errors.
The basic MyPy configuration this MR introduces is pretty lenient: it deliberately leaves two helpful typing rules switched off (disallow_untyped_calls
and disallow_untyped_defs
). That allows any piece of code to opt into typing annotations (instead of making them a hard requirement). Should the project team decide to go the stricter route, I’ll be there and willing to do follow-up MRs to add type declarations to the rest of the code.
This MR requires Python 3.10 or newer (compared to current master
, which requires 3.9 or newer).
Shouldn’t be an issue though, given that namcap runs on system Python anyway, which is at 3.11 3.12.