Description
The default way that mypy
gets invoked is with the arguments --show-error-end --no-error-summary --incremental --follow-imports silent
. Most of those are OK, but --follow-imports silent
will invalidate the cache if the same value isn't also present in the [tool.mypy]
section of pyproject.toml
.
The default value for this option is normal
.
The cache invalidation causes commandline invocations of mypy
to take much longer after having opened the editor, and causes the editor to take longer after having run mypy
from the commandline.
It's possible to reproduce this problem doing something like:
rm -r .mypy_cache/
time mypy . # ~12s (cold cache)
time mypy . # ~2s (warm cache)
nvim somefile.py # ...and quit after a few seconds
time mypy . # ~12s (cold cache again, due to invalidation)
There's two workarounds for this, either (somewhat inelegantly) hack the value back to its default:
[tool.pylsp-mypy]
overrides = [true, '--follow-imports', 'normal']
or just use 'silent' mode for all mypy invocations:
[tool.mypy]
follow_imports = 'silent'
A third option is to give mypy
a separate --cache-dir
when run from pylsp
, but this loses the benefit of sharing the cache between the two invocation modes (which is otherwise substantial).