See Missing imports in the docs.
- Install types cheatsheet
Be explicit that a module is local.
from . import foo foo.greet()
To import an object directly:
from .foo import greet
Unfortunately, any dot imports will break unless you use this approach for your CLI:
$ python -m my_app.my_module
This code is also valid to run.
import foo foo.greet()
But since it not clearly local, Mypy will think it is external (installed) and complain that it can’t be found.
error: Cannot find implementation or library stub for module named “foo”
You would run that as:
$ cd my_app $ python my_module.py
If you can’t find types for a library updating coding or installing packages, you can silence the Mypy errors.