pythonvisual-studio-codemypyvscode-python

Why is Visual Studio Code not showing mypy errors when I have my package installed in editable mode in a venv?


I have a Python project which uses mypy for type checking. The root of my project contains a setup.py and the package folder rise, along with a virtual environment folder venv. Both my shells and VSCode are set to use this virtual environment.

Most of the time, this setup works great: VSCode runs mypy every time I save and marks the errors with squiggles and in the Problems window. But for some reason, if I install the rise package in editable mode using pip install -e ., type checking in VSCode never finds any type errors. This does not happen if I install it in non-editable mode with pip install ., and if I uninstall the editable-mode package and reload the VSCode window, it immediately starts working normally again.


If I go into the Python output in the Output window, I see:

> ./venv/bin/python ~/.vscode/extensions/ms-python.python-2022.18.2/pythonFiles/linter.py -m mypy --show-column-numbers --strict ./rise/action.py

[...output from pylint, which is also configured and is working normally, clipped]

##########Linting Output - mypy##########

Success: no issues found in 1 source file

Yet if I copy and paste the command it's echoing into the terminal, there is in fact an error:

$ ./venv/bin/python ~/.vscode/extensions/ms-python.python-2022.18.2/pythonFiles/linter.py -m mypy --show-column-numbers --strict ./rise/action.py
rise/action.py:140:12: error: Incompatible return value type (got "None", expected "bool")  [return-value]

I'm stumped as to how to troubleshoot this further, and I haven't been able to find any reference to this issue anywhere on the web.


Solution

  • I ended up installing the Mypy extension for Visual Studio Code and removing mypy from my linters configuration. The extension doesn't suffer from this bug (or misconfiguration, or whatever it is), and it runs faster to boot.