Skip to content

indigoviolet/mypy-missing-imports

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mypy missing imports

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 or

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

Installing

$ 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

Usage

# 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

About

Handle missing imports in mypy efficiently

Resources

License

Stars

Watchers

Forks

Languages