How mypy handles imports
When mypy encounters an import
statement, it will firstattempt to locate that moduleor type stubs for that module in the file system. Mypy will thentype check the imported module. There are three different outcomesof this process:
- Mypy is unable to follow the import: the module either does notexist, or is a third party library that does not use type hints.
- Mypy is able to follow and type check the import, but you didnot want mypy to type check that module at all.
- Mypy is able to successfully both follow and type check themodule, and you want mypy to type check that module. The third outcome is what mypy will do in the ideal case. The followingsections will discuss what to do in the other two cases.