Erratic behavior with Mypy in VSCode: How to troubleshooting and solve?

Viewed 340

I have been having issues with MyPy in VSCode. I usually have my venv activated, Pylance as the language server and the MyPy extension (to perform check on editor change event). MyPy.

MyPy is installed on the current venv, is enabled, linting in enabled, and mypy is using the active interpreter, in my settings.json I have:

{
  "python.languageServer": "Pylance",
  "python.linting.enabled": true,
  "python.linting.mypyEnabled": true,
  "mypy.runUsingActiveInterpreter": true
}

MyPy does complain about "library stubs" not found, for packages that are not typed, it also points to some errors, but some very explicit ones are not being shown.

An example:

# file_a.py

def myfunc() -> dict:
    return {}
# file_b.py
from file_a import myfunc
from file_z import func_dont_exist 

# No error shown here
abc: bool = myfunc()
xyz: str = func_dont_exist()
# This points to an error, highlight the "1"
abc = "abc" + 1

If I run mypy . on the root, also no errors. I have mypy.ini file on the root, ignoring the migrations folder, .venv and usiing SQLMyPy Plugin.

If I disable the ignore_errors mypy point to a bunch of errors on the migration folders (expected), which tells me that the daemon is working.

I have updated my VSCode, tried to disable every extension I have, reloaded, restarted, checked the console, and nothing.

Running out of ideas on how to go by debugging this issue, every single question I find goes in the lines of: enable mypy on the settings, check the path, enable linting etc, but I've already done all of that.

Any ideas?

1 Answers

I had trouble with mypy in the past, like loading up mypy plugin. It was resolved when I started vscode from terminal with the right python environment activated

conda activate my-env
cd my/vs-code/project/dir
code .

Worth a try

Related