Skip to main content

Mypy linter for the Python LSP Server

Project description

https://badge.fury.io/py/pylsp-mypy.svg https://github.com/python-lsp/pylsp-mypy/workflows/Python%20package/badge.svg?branch=master

This is a plugin for the Python LSP Server.

It, like mypy, requires Python 3.8 or newer.

Installation

Install into the same virtualenv as python-lsp-server itself.

pip install pylsp-mypy

Configuration

pylsp-mypy supports the use of pyproject.toml for configuration. It can also be configuered using configs provided to the LSP server. The configuration keys are listed in the following.

Configuration

pyproject.toml key

LSP Configuration Key

Type

Description

Default

live_mode

pylsp.plugins.pylsp_mypy.live_mode

boolean

Provides type checking as you type. This writes to a tempfile every time a check is done. Turning off live_mode means you must save your changes for mypy diagnostics to update correctly.

true

dmypy

pylsp.plugins.pylsp_mypy.dmypy

boolean

Executes via dmypy run rather than mypy. This uses the dmypy daemon and may dramatically improve the responsiveness of the pylsp server, however this currently does not work in live_mode. Enabling this disables live_mode, even for conflicting configs.

false

strict

pylsp.plugins.pylsp_mypy.strict

boolean

Refers to the strict option of mypy. This option often is too strict to be useful.

false

overrides

pylsp.plugins.pylsp_mypy.overrides

array of (string items or true)

A list of alternate or supplemental command-line options. This modifies the options passed to mypy or the mypy-specific ones passed to dmypy run. When present, the special boolean member true is replaced with the command-line options that would’ve been passed had overrides not been specified.

[true]

dmypy_status_file

pylsp.plugins.pylsp_mypy.dmypy_status_file

string

Specifies which status file dmypy should use. This modifies the --status-file option passed to dmypy given dmypy is active.

.dmypy.json

config_sub_paths

pylsp.plugins.pylsp_mypy.config_sub_paths

array of string items

Specifies sub paths under which the mypy configuration file may be found. For each directory searched for the mypy config file, this also searches the sub paths specified here.

[]

report_progress

pylsp.plugins.pylsp_mypy.report_progress

boolean

Report basic progress to the LSP client. With this option, pylsp-mypy will report when mypy is running, given your editor supports LSP progress reporting. For small files this might produce annoying flashing in your editor, especially in live_mode. For large projects, enabling this can be helpful to assure yourself whether mypy is still running.

false

exclude

pylsp.plugins.pylsp_mypy.exclude

array of string items

A list of regular expressions which should be ignored. The mypy runner wil not be invoked when a document path is matched by one of the expressions. Note that this differs from the exclude directive of a mypy config which is only used for recursively discovering files when mypy is invoked on a whole directory. For both windows or unix platforms you should use forward slashes (/) to indicate paths.

[]

follow-imports

pylsp.plugins.pylsp_mypy.follow-imports

normal, silent, skip or error

mypy parameter follow-imports. In mypy this is normal by default. We set it silent, to sort out unwanted results. This can cause cash invalidation if you also run mypy in other ways. Setting this to normal avoids this at the cost of a small performance penalty.

silent

Using a pyproject.toml for configuration, which is in fact the preferred way, your configuration could look like this:

[tool.pylsp-mypy]
enabled = true
live_mode = true
strict = true
exclude = ["tests/*"]

A pyproject.toml does not conflict with the legacy config file (deprecated) given that it does not contain a pylsp-mypy section. The following explanation uses the syntax of the legacy config file (deprecated). However, all these options also apply to the pyproject.toml configuration (note the lowercase bools). Depending on your editor, the configuration (found in a file called pylsp-mypy.cfg in your workspace or a parent directory) should be roughly like this for a standard configuration:

{
    "enabled": True,
    "live_mode": True,
    "strict": False,
    "exclude": ["tests/*"]
}

With dmypy enabled your config should look like this:

{
    "enabled": True,
    "live_mode": False,
    "dmypy": True,
    "strict": False
}

With overrides specified (for example to tell mypy to use a different python than the currently active venv), your config could look like this:

{
    "enabled": True,
    "overrides": ["--python-executable", "/home/me/bin/python", True]
}

With dmypy_status_file your config could look like this:

{
    "enabled": True,
    "live_mode": False,
    "dmypy": True,
    "strict": False,
    "dmypy_status_file": ".custom_dmypy_status_file.json"
}

With config_sub_paths your config could look like this:

{
    "enabled": True,
    "config_sub_paths": [".config"]
}

With report_progress your config could look like this:

{
    "enabled": True,
    "report_progress": True
}

Developing

Install development dependencies with (you might want to create a virtualenv first):

pip install -r requirements.txt

The project is formatted with black. You can either configure your IDE to automatically format code with it, run it manually (black .) or rely on pre-commit (see below) to format files on git commit.

The project is formatted with isort. You can either configure your IDE to automatically sort imports with it, run it manually (isort .) or rely on pre-commit (see below) to sort files on git commit.

The project uses two rst tests in order to assure uploadability to pypi: rst-linter as a pre-commit hook and rstcheck in a GitHub workflow. This does not catch all errors.

This project uses pre-commit to enforce code-quality. After cloning the repository install the pre-commit hooks with:

pre-commit install

After that pre-commit will run all defined hooks on every git commit and keep you from committing if there are any errors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylsp_mypy-0.6.9.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

pylsp_mypy-0.6.9-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file pylsp_mypy-0.6.9.tar.gz.

File metadata

  • Download URL: pylsp_mypy-0.6.9.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pylsp_mypy-0.6.9.tar.gz
Algorithm Hash digest
SHA256 d28994a6ba123c3918ce3274a5cad768418650e575001002101c425ad6c7bbaa
MD5 0d7c81d865278740262b17f9fad0f8e0
BLAKE2b-256 9e5bd0a6c54ae8863bec81911965047d92662a13bc38dfb6fee6388d8419a72b

See more details on using hashes here.

File details

Details for the file pylsp_mypy-0.6.9-py3-none-any.whl.

File metadata

  • Download URL: pylsp_mypy-0.6.9-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for pylsp_mypy-0.6.9-py3-none-any.whl
Algorithm Hash digest
SHA256 9b73ece2977b22b5fc75dfec1cc491bf2031955e3da4062d924a5cc22a278151
MD5 d632627839763d2845fe603e745c140f
BLAKE2b-256 f3416f7db581bcd31895b4e5acdfd25f49a278898babda3f01a6d224b611b119

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page