Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: python-lsp/pylsp-mypy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.6.2
Choose a base ref
...
head repository: python-lsp/pylsp-mypy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jul 2, 2022

  1. ALso test on windows

    Richardk2n committed Jul 2, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    574c28e View commit details
  2. test action

    Richardk2n committed Jul 2, 2022
    Copy the full SHA
    6cdf1aa View commit details
  3. action test2

    Richardk2n committed Jul 2, 2022
    Copy the full SHA
    c9d3b28 View commit details
  4. fix action

    Richardk2n committed Jul 2, 2022
    Copy the full SHA
    49edaeb View commit details
  5. apply defaults

    Richardk2n committed Jul 2, 2022
    Copy the full SHA
    3d0cac4 View commit details
  6. fix tests

    Richardk2n committed Jul 2, 2022
    Copy the full SHA
    1a47bf3 View commit details

Commits on Jul 3, 2022

  1. Copy the full SHA
    bcb77d1 View commit details
  2. Format

    Richardk2n committed Jul 3, 2022
    Copy the full SHA
    5c1bd61 View commit details

Commits on Sep 16, 2022

  1. Copy the full SHA
    03975b7 View commit details

Commits on Sep 22, 2022

  1. Copy the full SHA
    2e5bfb9 View commit details
  2. black reformat

    rchl committed Sep 22, 2022
    Copy the full SHA
    ae88f1d View commit details
  3. 100 column limit

    rchl committed Sep 22, 2022
    Copy the full SHA
    d3b86ab View commit details

Commits on Oct 9, 2022

  1. Detect all errors

    Richardk2n authored Oct 9, 2022
    Copy the full SHA
    20db63a View commit details
  2. Merge pull request #40 from rchl/fix/generic-error

    Expose generic mypy error as a diagnostic
    Richardk2n authored Oct 9, 2022
    Copy the full SHA
    f12354d View commit details
  3. version bump

    Richardk2n authored Oct 9, 2022
    Copy the full SHA
    81cf8f4 View commit details

Commits on Nov 20, 2022

  1. update to newer actions

    Richardk2n authored Nov 20, 2022
    Copy the full SHA
    0f6e5d2 View commit details
  2. Update python-package.yml

    Richardk2n authored Nov 20, 2022
    Copy the full SHA
    2ce1a62 View commit details
  3. mypy 0.991 Support

    mypy now enables "--show-error-code" by default.
    Richardk2n committed Nov 20, 2022
    Copy the full SHA
    99cf687 View commit details
  4. test 3.11

    Richardk2n committed Nov 20, 2022
    Copy the full SHA
    94bf7b6 View commit details
  5. updata actions

    Richardk2n committed Nov 20, 2022
    Copy the full SHA
    67209ba View commit details
  6. Use status, kill, start, and check for dmypy

    Tanner Young authored and Richardk2n committed Nov 20, 2022
    Copy the full SHA
    5203947 View commit details
  7. Update pylsp_mypy/plugin.py

    Co-authored-by: StabbarN <921390+StabbarN@users.noreply.github.com>
    Richardk2n and StabbarN committed Nov 20, 2022
    Copy the full SHA
    7fc6229 View commit details
  8. Update pylsp_mypy/plugin.py

    Co-authored-by: StabbarN <921390+StabbarN@users.noreply.github.com>
    Richardk2n and StabbarN committed Nov 20, 2022
    Copy the full SHA
    8b70857 View commit details
  9. Merge pull request #45 from tyoung-patreon/dmypy-fixes

    Use status and restart for dmypy
    Richardk2n authored Nov 20, 2022
    Copy the full SHA
    1c5a336 View commit details

Commits on Dec 12, 2022

  1. version bump

    Richardk2n committed Dec 12, 2022
    Copy the full SHA
    b21f5af View commit details

Commits on Dec 17, 2022

  1. dmypy status-file closes #47

    Richardk2n committed Dec 17, 2022
    Copy the full SHA
    adf1572 View commit details
  2. Copy the full SHA
    93ed04d View commit details
  3. addresses #20

    Richardk2n committed Dec 17, 2022
    Copy the full SHA
    a4e3750 View commit details

Commits on Dec 31, 2022

  1. Create new config option 'config_names'

    This configuration option allows us to specify additional configuration
    file names under which the mypy config could be found.
    hetmankp authored and Richardk2n committed Dec 31, 2022
    Copy the full SHA
    36e6bf3 View commit details
  2. line length and format

    Richardk2n committed Dec 31, 2022
    Copy the full SHA
    be14272 View commit details

Commits on Jan 3, 2023

  1. Merge pull request #42 from hetmankp/master

    Create new config option 'config_sub_paths'
    Richardk2n authored Jan 3, 2023
    Copy the full SHA
    4de3d2d View commit details

Commits on Jan 5, 2023

  1. add simple progress reporting

    syphar authored and Richardk2n committed Jan 5, 2023
    Copy the full SHA
    73efe73 View commit details
  2. Spelling/grammar

    Co-authored-by: Rafał Chłodnicki <rchl2k@gmail.com>
    Richardk2n and rchl authored Jan 5, 2023
    Copy the full SHA
    33087a2 View commit details
  3. Merge pull request #48 from syphar/progress-reports

    add simple progress reporting
    Richardk2n authored Jan 5, 2023
    Copy the full SHA
    8ab82ea View commit details
  4. version bump

    Richardk2n committed Jan 5, 2023
    Copy the full SHA
    7237723 View commit details

Commits on Jan 18, 2023

  1. Fix #52. Remove stray output from dmypy

    There shouldn't be any output to stdout as this will mess the message
    stream when pylsp is running in stdout mode.
    lieryan committed Jan 18, 2023
    Copy the full SHA
    474ad1c View commit details

Commits on Feb 4, 2023

  1. format

    Richardk2n committed Feb 4, 2023
    Copy the full SHA
    cba6353 View commit details
  2. Merge pull request #53 from lieryan/lieryan-fix-stray-stdout-from-dmypy

    Remove stray output from dmypy
    Richardk2n authored Feb 4, 2023
    Copy the full SHA
    2b966ac View commit details
  3. specify encoding

    Richardk2n committed Feb 4, 2023
    Copy the full SHA
    90523f6 View commit details

Commits on Feb 25, 2023

  1. switch to tomli

    Richardk2n committed Feb 25, 2023
    Copy the full SHA
    77070a0 View commit details
  2. add config cache

    Richardk2n committed Feb 25, 2023
    Copy the full SHA
    0003369 View commit details
  3. Copy the full SHA
    c69be93 View commit details
  4. test

    Richardk2n committed Feb 25, 2023
    Copy the full SHA
    deaa7b5 View commit details
  5. fix tests

    Richardk2n committed Feb 25, 2023
    Copy the full SHA
    20cbcfa View commit details

Commits on Feb 26, 2023

  1. version bump

    Richardk2n committed Feb 26, 2023
    Copy the full SHA
    0ad251f View commit details
  2. Update setup.cfg

    Richardk2n committed Feb 26, 2023
    Copy the full SHA
    c055d36 View commit details

Commits on Apr 12, 2023

  1. Copy the full SHA
    a2536f7 View commit details
  2. Merge pull request #60 from gashihiko/fix/decode-error-on-non-utf-8-e…

    …nvironment
    
    Fix decode error on non-utf8 environments
    Richardk2n authored Apr 12, 2023
    Copy the full SHA
    6fd72c3 View commit details

Commits on Apr 16, 2023

  1. Copy the full SHA
    ce0adbf View commit details
  2. Copy the full SHA
    5ccd7ee View commit details
Showing with 878 additions and 210 deletions.
  1. +13 −9 .github/workflows/python-package.yml
  2. +2 −2 .github/workflows/python-publish.yml
  3. +2 −2 .pre-commit-config.yaml
  4. +1 −1 LICENSE
  5. +127 −18 README.rst
  6. +1 −1 pylsp_mypy/_version.py
  7. +370 −107 pylsp_mypy/plugin.py
  8. +1 −1 pyproject.toml
  9. +2 −3 requirements.txt
  10. +11 −7 setup.cfg
  11. +348 −59 test/test_plugin.py
22 changes: 13 additions & 9 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -9,18 +9,24 @@ on:
pull_request:
branches: [ master ]

defaults:
run:
shell: bash

jobs:

testCode:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
@@ -31,9 +37,7 @@ jobs:
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --show-source --statistics
- name: Check black formatting
run: |
# stop the build if black detect any changes
@@ -51,9 +55,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ repos:
hooks:
- id: rst-linter
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- id: isort
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2017 Tom van Ommeren
Copyright (c) 2022 Richard Kellnberger
Copyright (c) 2025 Richard Kellnberger

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
145 changes: 127 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
@@ -11,7 +11,9 @@ This is a plugin for the `Python LSP Server`_.

.. _`Python LSP Server`: https://github.com/python-lsp/python-lsp-server

It, like mypy, requires Python 3.7 or newer.
It, like `mypy`_, requires Python 3.9 or newer.

.. _`mypy`: https://github.com/python/mypy


Installation
@@ -23,37 +25,95 @@ Install into the same virtualenv as python-lsp-server itself.

Configuration
-------------

``live_mode`` (default is True) 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.

``dmypy`` (default is False) 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.

``strict`` (default is False) refers to the ``strict`` option of ``mypy``.
This option often is too strict to be useful.

``overrides`` (default is ``[True]``) specifies 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. Later options take precedence, which allows for replacing or negating individual default options (see ``mypy.main:process_options`` and ``mypy --help | grep inverse``).

This project supports the use of ``pyproject.toml`` for configuration. It is in fact the preferred way. Using that your configuration could look like this:
``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.

.. list-table:: Configuration
:header-rows: 1

* - ``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 cache invalidation if you also run ``mypy`` in other ways. Setting this to ``normal`` avoids this at the cost of a small performance penalty.
- ``silent``
* - ``mypy_command``
- ``pylsp.plugins.pylsp_mypy.mypy_command``
- ``array`` of ``string`` items
- **The command to run mypy**. This is useful if you want to run mypy in a specific virtual environment. Requires env variable ``PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`` to be set.
- ``[]``
* - ``dmypy_command``
- ``pylsp.plugins.pylsp_mypy.dmypy_command``
- ``array`` of ``string`` items
- **The command to run dmypy**. This is useful if you want to run dmypy in a specific virtual environment. Requires env variable ``PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`` to be set.
- ``[]``

Both ``mypy_command`` and ``dmypy_command`` could be used by a malicious repo to execute arbitrary code by looking at its source with this plugin active.
Still users want this feature. For security reasons this is disabled by default. If you really want it and accept the risks set the environment variable ``PYLSP_MYPY_ALLOW_DANGEROUS_CODE_EXECUTION`` in order to activate it.

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 given that it does not contain a ``pylsp-mypy`` section. The following explanation uses the syntax of the legacy config file. 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:
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
"strict": False,
"exclude": ["tests/*"]
}

With ``dmypy`` enabled your config should look like this:
@@ -76,6 +136,55 @@ With ``overrides`` specified (for example to tell mypy to use a different python
"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
}

With ``mypy_command`` your config could look like this:

::

{
"enabled": True,
"mypy_command": ["poetry", "run", "mypy"]
}

With ``dmypy_command`` your config could look like this:

::

{
"enabled": True,
"live_mode": False,
"dmypy": True,
"dmypy_command": ["/path/to/venv/bin/dmypy"]
}

Developing
-------------
2 changes: 1 addition & 1 deletion pylsp_mypy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.2"
__version__ = "0.7.0"
477 changes: 370 additions & 107 deletions pylsp_mypy/plugin.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ live_mode = true
strict = true

[tool.mypy]
python_version = "3.7"
python_version = "3.9"

[[tool.mypy.overrides]]
module = "pylsp.*"
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
python-lsp-server
mypy
toml
types-toml
mypy >= 0.981
tomli >= 1.1.0 ; python_version < "3.11"
black
pre-commit
rstcheck
18 changes: 11 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pylsp-mypy
author = Tom van Ommeren, Richard Kellnberger
author = Richard Kellnberger, Tom van Ommeren
description = Mypy linter for the Python LSP Server
url = https://github.com/python-lsp/pylsp-mypy
long_description = file: README.rst
@@ -10,19 +10,23 @@ classifiers =
Intended Audience :: Developers
Topic :: Software Development
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: 3.13

[options]
python_requires = >= 3.7
python_requires = >= 3.9
packages = find:
install_requires =
python-lsp-server
mypy
toml
python-lsp-server >=1.7.0
mypy >= 0.981
tomli >= 1.1.0 ; python_version < "3.11"

[flake8]
max-complexity = 20
max-line-length = 100

[options.entry_points]
pylsp = pylsp_mypy = pylsp_mypy.plugin
407 changes: 348 additions & 59 deletions test/test_plugin.py

Large diffs are not rendered by default.