Skip to content

mypy: bare-bone configuration and make target ("typecheck")

First attempt at trying to have a clean mypy pass on our code base. This change just adds support for "make typecheck", not used anywhere unless explicitly invoked in specific module dirs.

With this conf it is already possible to cleanly typecheck swh.{model, core, objstorage}, provided that some additional minor changes are committed in the respective repos---changes that I also have in separate diffs, but that will need to wait for Python >= 3.6, as they require PEP 526 variable annotations.

Interestingly enough, even if these are still mostly no-op mypy run, making mypy pass made me find a couple of minor bugs (e.g., missing optional "import" statements hidden by "# noqa" annotations that were added for unrelated reasons).

Test Plan

$ cd swh-model ; make typecheck
PYTHONPATH=... mypy --config-file ../mypy.ini -p swh.model
swh/model/merkle.py:273: error: Need type annotation for '__slots__' (hint: "__slots__: List[<type>] = ...")
swh/model/hashutil.py:73: error: Need type annotation for '_blake2_hash_cache' (hint: "_blake2_hash_cache: Dict[<type>, <type>] = ...")
[...]

Migrated from D1983 (view on Phabricator)

Merge request reports