Mypy Linter for Python LSP Server
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.
Common errors
-
Cannot find implementation or library stub for module named "module name"
cause Mypy cannot find a module imported in your code, often a local custom module or a third-party library whose stubs are not properly installed/detected. This can be due to an incorrect Python environment or `mypy_path` configuration.fixEnsure `mypy` is running in the correct virtual environment with all project dependencies installed. Verify that your `pyproject.toml` (or `mypy.ini`) correctly specifies `mypy_path` if you have custom source directories not at the project root. For third-party libraries, ensure type stubs are installed (e.g., `pip install types-yourlibrary`). -
Client X quit with exit code 1 and signal 0 (or Python LSP server not running)
cause The `python-lsp-server` (which hosts `pylsp-mypy`) failed to start. This often happens after Python interpreter updates, virtual environment corruption, or missing core dependencies for `python-lsp-server` itself.fixReinstall `python-lsp-server`, `pylsp-mypy`, and `mypy` in a clean virtual environment: `pip uninstall -y pylsp-mypy python-lsp-server mypy && pip install python-lsp-server pylsp-mypy mypy`. Verify that the base `python-lsp-server` works before diagnosing `pylsp-mypy` specific issues. -
ERROR Missing dependencies: setuptools>=40.8.0 validate-pyproject -> fastjsonschema<=3,>=2.16.2
cause A dependency conflict, typically an older version of `fastjsonschema` is installed or a local `pip install` interfered with system packages. `pylsp-mypy` relies on `validate-pyproject` which has a dependency on `fastjsonschema`.fixExplicitly install or upgrade `fastjsonschema` to a compatible version: `pip install "fastjsonschema>=2.16.2"`. Consider recreating your virtual environment to resolve potential conflicts.
Warnings
- breaking Python 3.10 is now the minimum required Python version.
- gotcha Enabling `dmypy` (daemon mode) currently disables `live_mode`.
- gotcha Default `--follow-imports silent` can invalidate `mypy`'s cache.
- gotcha Using `mypy_command` or `dmypy_command` requires an explicit environment variable for security reasons.
Install
-
pip install pylsp-mypy
Imports
- pylsp-mypy
This library is a plugin and is not typically imported directly in user code. It is loaded and configured by the Python LSP Server.
Quickstart
# 1. Install pylsp-mypy (and python-lsp-server) in your project's virtual environment: pip install python-lsp-server pylsp-mypy mypy # 2. Add or update your pyproject.toml to enable and configure pylsp-mypy: # (This example enables live mode and strict checking) # [tool.pylsp-mypy] # enabled = true # live_mode = true # strict = true # exclude = ["tests/*"] # 3. Open a Python file in your LSP-compatible editor (e.g., VS Code, Neovim, Emacs) # The LSP server will automatically detect and load pylsp-mypy for type checking.