Page MenuHomeSoftware Heritage

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

Authored by zack on Sep 15 2019, 10:58 AM.

Details

Summary

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>] = ...")
[...]

Diff Detail

Repository
rDENV Development environment
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

  • add untyped deps to make swh-loader-core pass

but that will need to wait for Python >= 3.6, as they require PEP 526 variable annotations.

What about type comments?

but that will need to wait for Python >= 3.6, as they require PEP 526 variable annotations.

What about type comments?

I'd rather not do the annotation work twice, given we're soon going to be on Python 3.7 anyway (T1981).

  • typecheck: rely on "pip list" to generate MYPYPATH
  • typecheck: do not fiddle with MYPYPHATH and rely on PEP 561 instead
This revision is now accepted and ready to land.Sep 17 2019, 6:40 AM
This revision was automatically updated to reflect the committed changes.