When enabling mypy in vscode ("python.linting.mypyEnabled": true,
),
then any manual mypy commands become very slow and CPU intensive (10s before vs 3min after).
It seems like the two mypy processes should be independent, or even aid each other through a cache, but they seem to be in each other’s way.
I noticed that from a clean venv it doesn’t happen for a while. Only after the vscode has run mypy do the manual mypy commands become slow, even when vscode is not running anymore.
The only related question I could find was this.
2
Answers
I found that making vscode use a different cache directory resolves the problem. Consider adding e.g. the following to your
settings.json
:Bonus: by remaining within the default directory (
mypy_cache
), the second cache directory is ignored bygit
.I used to have problems with slow and memory consuming
mypy
too. I have a guess that it may be because VSCode is trying to index a rather largemypy_cache
. I added the cache to the settings in the"files.exclude"
and"python.linting.ignorePatterns"
sections and it got better. It’s also useful to add any other caches you have to these sections:pycache
,pytest_cache
, etc