pylsp-mypy is a plugin for the Python LSP Server that integrates Mypy for static type checking. It provides live diagnostics as you type or on file save. The library is currently at version 0.7.1 and maintains an active release cadence, frequently updating to support new `mypy` and `python-lsp-server` features and bug fixes.
pip install pylsp-mypyVerified import paths — ran on the pinned version, not inferred.
To use `pylsp-mypy`, install it alongside `python-lsp-server` and `mypy` in your development environment. Configuration is typically done via a `[tool.pylsp-mypy]` section in your `pyproject.toml` file, where you can enable it, set `live_mode` for as-you-type checks, and enable `strict` Mypy rules.
Ensure your development environment and `python-lsp-server` run on Python 3.10 or newer. If you are on an older Python version, you must use an earlier `pylsp-mypy` version (e.g., 0.6.x supports Python 3.8+).
If you want real-time type checking as you type, keep `dmypy = false` (the default) and `live_mode = true`. If you prioritize faster checks on save for large projects, set `dmypy = true` and accept that `live_mode` will be implicitly disabled.
The default `pylsp-mypy` invocation of `mypy` uses `--follow-imports silent`. If you run `mypy` from the command line with its default `--follow-imports normal`, this mismatch will cause `mypy`'s cache to be invalidated, slowing down subsequent runs. To prevent this, either configure `[tool.pylsp-mypy] overrides = [true, '--follow-imports', 'normal']` or set `[tool.mypy] follow_imports = 'silent'` in your `pyproject.toml`.
If you customize the `mypy_command` or `dmypy_command` to run `mypy` from a specific virtual environment or using a wrapper (e.g., `poetry run mypy`), you must set the environment variable `PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`. This is a security measure to prevent arbitrary code execution from potentially malicious project configurations.