Generate missing imports excludes for mypy.
Mypy’s handling of missing imports can be cumbersome:
- many packages don’t have type definitions included, though this number is hopefully decreasing over time
- mypy will show an error like
Skipping analyzing '<module>': found module but no type hints or library stubs
orCannot find implementation or library stub for module named <module>
if type definitions aren’t found or the module is not resolved.
- Globally turning on the
ignore_missing_imports
option is not recommended. - The recommended option (in case you cannot find a type definition or write
your own) is to exclude each such library individually in
mypy.ini
, which gets annoying.
This tool lets you handle this more efficiently.
- Remember to add
warn_unused_configs=true
to your mypy config to warn you if these excludes get out of date.
$ pip install git+https://github.com/indigoviolet/mypy-missing-imports
# OR
$ poetry add git+https://github.com/indigoviolet/mypy-missing-imports
# OR
$ pipx install git+https://github.com/indigoviolet/mypy-missing-imports
# will directly edit the mypy.ini file
$ mypy_missing_imports mypy.ini
> mypy --config-file /tmp/mypy_5axuqvna.ini .
> Found missing imports for tomlkit,snoop
> Updated file mypy.ini
# prints out the sections so you can edit or include manually
$ mypy_missing_imports
> mypy --config-file /tmp/mypy_5axuqvna.ini .
> Found missing imports for tomlkit,snoop
[mypy-snoop.*]
ignore_missing_imports = true
[mypy-tomlkit.*]
ignore_missing_imports = true