Skip to content
Advertisement

Python linter in vscode with incomplete type checking (Expected… got…)

I use vscode and I found the Python linter(s) do not detect when a python function is invoked with a parameter of different type than it’s signature defines.

In this case, the function expects a typing.Type[Exception] instead of Exception:

enter image description here

Pycharm detects this situation:

enter image description here

I think mypy does not detect this one because it uses the typing module (mypy detects type mismatch in builtin types).

  • Is there a way to configure mypy to detect cases like this?
  • Which is the linter pycharm uses? Does it exist in vscode?
  • Is there another linter that could do the job?

Note: I followed the flag suggestion from this SO post (--check-untyped-defs) but it didn’t work.

Advertisement

Answer

After following the suggestions in the comment section, I was able to do this in vscode by:

  1. Installing the Pylance plugin and
  2. Setting the following params on the User Settings:
    "python.languageServer": "Pylance",
    "python.analysis.typeCheckingMode": "strict",
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement