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
:
Pycharm detects this situation:
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:
- Installing the
Pylance
plugin and - Setting the following params on the User Settings:
"python.languageServer": "Pylance", "python.analysis.typeCheckingMode": "strict",