Configure Mypy in VSCode to enforce type hinting

Viewed 4262

I want to configure Mypy on Visual Studio Code to enforce type hinting in my project.

I use the following configuration

"python.linting.pylintArgs": [
        "--disable=W0611"
    ],
    "python.linting.mypyEnabled":true,
    "python.linting.mypyCategorySeverity.note":"Warning",
    "python.linting.mypyArgs": [

        "--ignore-missing-imports",
        "--follow-imports=silent",
        "--show-column-numbers",
        "--disallow-untyped-defs=True",
        "--disallow-untyped-calls=True",
        "--check-untyped-defs=True",
        "--no-implicit-optional=True",

    ]

However I have some functions with no type annotations and I do not get any info, warning or errors about them. Actually Mypy doesn't seem to work. It actually only catches false-positive when I remove the "no-implicit-optional" option.

What am I missing ?

1 Answers

I found an answer here, and then realized my mistake. Adding the "=True" in the mypyArgs was wrong.

Here are my new settings :

{
    "python.pythonPath": "C:\\Program Files\\Python37\\python.exe",
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.linting.pylintArgs": [
 
        "--disable=W0611"
    ],
    "python.linting.mypyEnabled": true,
    "python.linting.mypyCategorySeverity.error":"Warning",
    "python.linting.mypyArgs": [
        "--ignore-missing-imports",
        "--follow-imports=silent",
        "--show-column-numbers",
        "--disallow-untyped-defs",
        "--disallow-untyped-calls"
    ]

}
Related