Page MenuHomeSoftware Heritage

typing: minimal changes to make a no-op mypy run pass

Authored by zack on Sep 20 2019, 11:22 AM.



This is a first, proof of concept diff showing how we can add mypy support to
our modules. A second one is coming next, for swh-model. There is more where
these come from, but I'd like to take the change of these first two to see if
this is something we like and is useful.

Note that this is only to make a bare-bone mypy run pass cleanly, it does *not*
add type annotations to the swh.core API. That can be done next, gradually;
there is no hurry. Still, having mypy pass allows to detect glaring type
errors, dunno, "1 + {}" expressions that would otherwise pass unnoticed.

About pre-buster Python compatibility: I'm using here comments for variable
annotations instead of PEP 526 which requires Python >= 3.6. I'm doing so to
avoid breaking production, but I don't know how to easily check that this is
fully Python 3.5 compatible---independent testing on this point is very

Test Plan

tox -e mypy

(or just tox, as the environment is added to the default list of tox envs)

Diff Detail

rDCORE Foundations and core functionalities
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

zack created this revision.Sep 20 2019, 11:22 AM
zack updated this revision to Diff 6771.Sep 20 2019, 11:30 AM
  • mypy: use conffile to ignore requests_mock
vlorentz accepted this revision.Sep 20 2019, 11:37 AM
This revision is now accepted and ready to land.Sep 20 2019, 11:37 AM
zack updated this revision to Diff 6772.Sep 20 2019, 12:04 PM
  • mypy: ignore django-stubs, needed only by hypothesis