Page MenuHomeSoftware Heritage

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

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

Details

Summary

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
welcome.

Test Plan

tox -e mypy

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

Diff Detail

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

Event Timeline

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