{"id":7583,"library":"pylsp-mypy","title":"Mypy Linter for Python LSP Server","description":"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.","status":"active","version":"0.7.1","language":"en","source_language":"en","source_url":"https://github.com/python-lsp/pylsp-mypy","tags":["LSP","Mypy","type checking","static analysis","Python","plugin","developer tools"],"install":[{"cmd":"pip install pylsp-mypy","lang":"bash","label":"Install pylsp-mypy"}],"dependencies":[{"reason":"pylsp-mypy is a plugin for the Python LSP Server, which must be installed in the same virtual environment.","package":"python-lsp-server","optional":false},{"reason":"Provides the core static type checking functionality that pylsp-mypy integrates.","package":"mypy","optional":false},{"reason":"Used for parsing `pyproject.toml` configuration files.","package":"tomli","optional":true},{"reason":"Often a dependency for validating `pyproject.toml` configuration, sometimes causing build issues with older versions.","package":"fastjsonschema","optional":true}],"imports":[{"note":"pylsp-mypy functions as an extension to the Python LSP Server. Its features are enabled and configured via the LSP client's settings or a `pyproject.toml` file, rather than direct Python imports.","symbol":"pylsp-mypy","correct":"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":{"code":"# 1. Install pylsp-mypy (and python-lsp-server) in your project's virtual environment:\npip install python-lsp-server pylsp-mypy mypy\n\n# 2. Add or update your pyproject.toml to enable and configure pylsp-mypy:\n# (This example enables live mode and strict checking)\n# [tool.pylsp-mypy]\n# enabled = true\n# live_mode = true\n# strict = true\n# exclude = [\"tests/*\"]\n\n# 3. Open a Python file in your LSP-compatible editor (e.g., VS Code, Neovim, Emacs)\n# The LSP server will automatically detect and load pylsp-mypy for type checking.","lang":"python","description":"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."},"warnings":[{"fix":"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+).","message":"Python 3.10 is now the minimum required Python version.","severity":"breaking","affected_versions":"0.7.0 and later"},{"fix":"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.","message":"Enabling `dmypy` (daemon mode) currently disables `live_mode`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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`.","message":"Default `--follow-imports silent` can invalidate `mypy`'s cache.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Using `mypy_command` or `dmypy_command` requires an explicit environment variable for security reasons.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure `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`).","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.","error":"Cannot find implementation or library stub for module named \"module name\""},{"fix":"Reinstall `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.","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.","error":"Client X quit with exit code 1 and signal 0 (or Python LSP server not running)"},{"fix":"Explicitly install or upgrade `fastjsonschema` to a compatible version: `pip install \"fastjsonschema>=2.16.2\"`. Consider recreating your virtual environment to resolve potential conflicts.","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`.","error":"ERROR Missing dependencies: setuptools>=40.8.0 validate-pyproject -> fastjsonschema<=3,>=2.16.2"}]}