A single [import] error can hide many other errors in completely unrelated code
I work on a large legacy codebase with thousands of type errors. I have found recently that our configuration had ignore_missing_imports = True to account for the absence of a many of 3rd-party deps in our typechecking venv. In an attempt to improve typechecking strictness, I added a per-package stanza to enable ignore_missing_imports = False for import paths belonging to our internal code.
I found that:
- this revealed a handful of cases where import statements in
if TYPE_CHECKING:block had invalid/outdated paths - the presence of even a single such invalid import in the entire codebase, even in a file that is not imported anywhere, will mask most of the existing errors from mypy's output, even though mypy does appear to check the same number of files
For instance, prior to enabling the stricter import check I get:
...
Found 2830 errors in 815 files (checked 11667 source files)
with the stricter import check, if any import path is invalid, I get:
...
Found 182 errors in 78 files (checked 11667 source files)
This is on macOS, with mypy 0.971
Unfortunately the codebase is not public and I have not yet managed to create a minimal reproducer.