curved-television-6568
03/31/2021, 12:08 PMpants.toml
:
[mypy]
config = "mypy.ini"
args = "--namespace-packages --explicit-package-bases"
and in mypy.ini
:
[mypy]
mypy_path = src:plugins
Any paths under which you have sources, but that aren’t part of the package name. So in this case, there are sources in src/<namespaceroot-pkgs>/…
and plugins/<other-pkgs>/…
To aid in debugging this, the -v
flag to mypy was really helpful, so you can inspect the output from mypy, on the form:
LOG: Found source: BuildSource(path='plugins/xx/flask/rest/routes/generic.py', module='xx.flask.rest.routes.generic', has_text=False, base_dir='/private/var/folders/8j/c8jf_msj009947wyw82xvdkw0000gn/T/process-executionLIFk6M/plugins')
Here, the BuildSource(…, module=)
will show which module mypy thinks the source is in.
Relevant (and helpful) mypy docs: https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modulesenough-analyst-54434
03/31/2021, 12:33 PMnamespace_packages = True
into mypy.ini, and in the next release of mypy, explicit_package_bases = True
as well so that your mypy setup is self-contained and works outside of Pants too which is always useful for debugging.