Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: pylsp-mypy
3 Version: 0.7.1
4 Summary: Mypy linter for the Python LSP Server
5 Home-page: https://github.com/python-lsp/pylsp-mypy
6 Author: Richard Kellnberger, Tom van Ommeren
7 License: 'MIT'
8 Classifier: Development Status :: 4 - Beta
9 Classifier: Intended Audience :: Developers
10 Classifier: Topic :: Software Development
11 Classifier: License :: OSI Approved :: MIT License
12 Classifier: Programming Language :: Python :: 3.9
13 Classifier: Programming Language :: Python :: 3.10
14 Classifier: Programming Language :: Python :: 3.11
15 Classifier: Programming Language :: Python :: 3.12
16 Classifier: Programming Language :: Python :: 3.13
17 Requires-Python: >=3.10
18 Description-Content-Type: text/x-rst
19 License-File: LICENSE
20 Requires-Dist: python-lsp-server>=1.13.1
21 Requires-Dist: mypy>=0.981
22 Requires-Dist: tomli>=1.1.0; python_version < "3.11"
23 Provides-Extra: test
24 Requires-Dist: tox; extra == "test"
25 Requires-Dist: pytest; extra == "test"
26 Requires-Dist: pytest-cov; extra == "test"
27 Requires-Dist: coverage; extra == "test"
28 Dynamic: description-content-type
29 Dynamic: license-file
30
31 Mypy plugin for PYLSP
32 ======================
33
34 .. image:: https://badge.fury.io/py/pylsp-mypy.svg
35 :target: https://badge.fury.io/py/pylsp-mypy
36
37 .. image:: https://github.com/python-lsp/pylsp-mypy/workflows/Python%20package/badge.svg?branch=master
38 :target: https://github.com/python-lsp/pylsp-mypy/
39
40 This is a plugin for the `Python LSP Server`_.
41
42 .. _`Python LSP Server`: https://github.com/python-lsp/python-lsp-server
43
44 It, like `mypy`_, requires Python 3.10 or newer.
45
46 .. _`mypy`: https://github.com/python/mypy
47
48
49 Installation
50 ------------
51
52 Install into the same virtualenv as python-lsp-server itself.
53
54 ``pip install pylsp-mypy``
55
56 Configuration
57 -------------
58 ``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.
59
60 .. list-table:: Configuration
61 :header-rows: 1
62
63 * - ``pyproject.toml`` key
64 - LSP Configuration Key
65 - Type
66 - Description
67 - Default
68 * - ``live_mode``
69 - ``pylsp.plugins.pylsp_mypy.live_mode``
70 - ``boolean``
71 - **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.
72 - true
73 * - ``dmypy``
74 - ``pylsp.plugins.pylsp_mypy.dmypy``
75 - ``boolean``
76 - **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.
77 - false
78 * - ``strict``
79 - ``pylsp.plugins.pylsp_mypy.strict``
80 - ``boolean``
81 - **Refers to the** ``strict`` **option of** ``mypy``. This option often is too strict to be useful.
82 - false
83 * - ``overrides``
84 - ``pylsp.plugins.pylsp_mypy.overrides``
85 - ``array`` of (``string`` items or ``true``)
86 - **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.
87 - ``[true]``
88 * - ``dmypy_status_file``
89 - ``pylsp.plugins.pylsp_mypy.dmypy_status_file``
90 - ``string``
91 - **Specifies which status file dmypy should use**. This modifies the ``--status-file`` option passed to ``dmypy`` given ``dmypy`` is active.
92 - ``.dmypy.json``
93 * - ``config_sub_paths``
94 - ``pylsp.plugins.pylsp_mypy.config_sub_paths``
95 - ``array`` of ``string`` items
96 - **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.
97 - ``[]``
98 * - ``report_progress``
99 - ``pylsp.plugins.pylsp_mypy.report_progress``
100 - ``boolean``
101 - **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.
102 - false
103 * - ``exclude``
104 - ``pylsp.plugins.pylsp_mypy.exclude``
105 - ``array`` of ``string`` items
106 - **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.
107 - ``[]``
108 * - ``follow-imports``
109 - ``pylsp.plugins.pylsp_mypy.follow-imports``
110 - ``normal``, ``silent``, ``skip`` or ``error``
111 - ``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.
112 - ``silent``
113 * - ``mypy_command``
114 - ``pylsp.plugins.pylsp_mypy.mypy_command``
115 - ``array`` of ``string`` items
116 - **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.
117 - ``[]``
118 * - ``dmypy_command``
119 - ``pylsp.plugins.pylsp_mypy.dmypy_command``
120 - ``array`` of ``string`` items
121 - **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.
122 - ``[]``
123
124 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.
125 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.
126
127 Using a ``pyproject.toml`` for configuration, which is in fact the preferred way, your configuration could look like this:
128
129 ::
130
131 [tool.pylsp-mypy]
132 enabled = true
133 live_mode = true
134 strict = true
135 exclude = ["tests/*"]
136
137 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).
138 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:
139
140 ::
141
142 {
143 "enabled": True,
144 "live_mode": True,
145 "strict": False,
146 "exclude": ["tests/*"]
147 }
148
149 With ``dmypy`` enabled your config should look like this:
150
151 ::
152
153 {
154 "enabled": True,
155 "live_mode": False,
156 "dmypy": True,
157 "strict": False
158 }
159
160 With ``overrides`` specified (for example to tell mypy to use a different python than the currently active venv), your config could look like this:
161
162 ::
163
164 {
165 "enabled": True,
166 "overrides": ["--python-executable", "/home/me/bin/python", True]
167 }
168
169 With ``dmypy_status_file`` your config could look like this:
170
171 ::
172
173 {
174 "enabled": True,
175 "live_mode": False,
176 "dmypy": True,
177 "strict": False,
178 "dmypy_status_file": ".custom_dmypy_status_file.json"
179 }
180
181 With ``config_sub_paths`` your config could look like this:
182
183 ::
184
185 {
186 "enabled": True,
187 "config_sub_paths": [".config"]
188 }
189
190 With ``report_progress`` your config could look like this:
191
192 ::
193
194 {
195 "enabled": True,
196 "report_progress": True
197 }
198
199 With ``mypy_command`` your config could look like this:
200
201 ::
202
203 {
204 "enabled": True,
205 "mypy_command": ["poetry", "run", "mypy"]
206 }
207
208 With ``dmypy_command`` your config could look like this:
209
210 ::
211
212 {
213 "enabled": True,
214 "live_mode": False,
215 "dmypy": True,
216 "dmypy_command": ["/path/to/venv/bin/dmypy"]
217 }
218
219 Developing
220 -------------
221
222 Install development dependencies with (you might want to create a virtualenv first):
223
224 ::
225
226 pip install -r requirements.txt
227
228 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.
229
230 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.
231
232 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.
233
234 This project uses `pre-commit`_ to enforce code-quality. After cloning the repository install the pre-commit hooks with:
235
236 ::
237
238 pre-commit install
239
240 After that pre-commit will run `all defined hooks`_ on every ``git commit`` and keep you from committing if there are any errors.
241
242 .. _black: https://github.com/psf/black
243 .. _isort: https://github.com/PyCQA/isort
244 .. _rst-linter: https://github.com/Lucas-C/pre-commit-hooks-markup
245 .. _rstcheck: https://github.com/myint/rstcheck
246 .. _pre-commit: https://pre-commit.com/
247 .. _all defined hooks: .pre-commit-config.yaml