matangover / mypy-vscode

VS Code extension that provides type checking and analysis for Python code using mypy.
https://marketplace.visualstudio.com/items?itemName=matangover.mypy
Other
93 stars 16 forks source link

Mypy extension for VS Code

Runs mypy on Python code to provide type checking.

Installing mypy

This extension requires mypy to be installed on your system. To install mypy, run pip install mypy. There are other ways to install mypy, such as using pipx or your system's package manager.

By default, this extension relies on having the dmypy executable available on your PATH. This should be the case if you installed mypy globally. To use a different mypy installation, set the mypy.dmypyExecutable setting.

Some people prefer to have mypy installed in each project's virtual environment rather than in a global location. To do this, enable mypy.runUsingActiveInterpreter (either globally or for a specific workspace).

Using the extension

The extension automatically checks the workspace with Mypy if there are Python files in it. Diagnostics generated by Mypy are shown in the editor and in the Problems panel.

Every time you save a Python file, the extension will re-run Mypy. Only the changed files (and their dependents) will be re-analyzed.

The extension also provides the following commands:

Configuration

To configure mypy, you can create a mypy.ini file in your workspace folder (or any of the default locations). See mypy configuration file. You can also specify a custom path to mypy.ini using the mypy.configFile setting.

To configure the mypy-vscode extension, use the following VS Code settings:

Experimental: Type checking in notebooks

This extension can also run mypy on Python code cells in Jupyter notebooks. To enable this feature, set mypy.checkNotebooks to true. Notebooks are type checked when they're opened or saved.

For notebooks, we use mypy rather than dmypy. Use the mypy.mypyExecutable setting to control the mypy executable path. Most settings like mypy.runUsingActiveInterpreter, mypy.configFile, mypy.extraArguments are honored for notebooks too.

There are a couple of known issues:

License

This project is made available under the MIT License.