Skip to content

Commit ce3844f

Browse files
committed
minor readability changes
1 parent a83609e commit ce3844f

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ With ``dmypy`` enabled your config should look like this:
5757
"strict": False
5858
}
5959

60-
With ``overrides`` specified, your config should resemble this:
60+
With ``overrides`` specified (for example to tell mypy to use a different python than the currently active venv), your config could look like this:
6161

6262
::
6363

6464
{
65-
...,
65+
"enabled": True,
6666
"overrides": ["--python-executable", "/home/me/bin/python", True]
6767
}
6868

pylsp_mypy/plugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ def parse_line(line: str, document: Optional[Document] = None) -> Optional[Dict[
9797

9898
def apply_overrides(args: List[str], overrides: List[Any]) -> List[str]:
9999
"""Replace or combine default command-line options with overrides."""
100-
o = iter(overrides)
101-
if True not in o:
100+
overrides_iterator = iter(overrides)
101+
if True not in overrides_iterator:
102102
return overrides
103-
rest = list(o)
104-
return [*overrides[: -(len(rest) + 1)], *args, *rest]
103+
# If True is in the list, the if above leaves the iterator at the element after True,
104+
# therefore, the list below only contains the elements after the True
105+
rest = list(overrides_iterator)
106+
# slice of the True and the rest, add the args, add the rest
107+
return overrides[: -(len(rest) + 1)] + args + rest
105108

106109

107110
@hookimpl
@@ -195,12 +198,11 @@ def pylsp_lint(
195198
if settings.get("strict", False):
196199
args.append("--strict")
197200

198-
overrides = settings.get("overrides")
201+
overrides = settings.get("overrides", [True])
199202

200203
if not dmypy:
201204
args.extend(["--incremental", "--follow-imports", "silent"])
202-
if overrides:
203-
args = apply_overrides(args, overrides)
205+
args = apply_overrides(args, overrides)
204206

205207
log.info("executing mypy args = %s", args)
206208
completed_process = subprocess.run(
@@ -214,15 +216,17 @@ def pylsp_lint(
214216
# If daemon is hung, kill will reset
215217
# If daemon is dead/absent, kill will no-op.
216218
# In either case, reset to fresh state
217-
completed_process = subprocess.run(["dmypy", *args], stderr=subprocess.PIPE)
219+
completed_process = subprocess.run(
220+
["dmypy", *apply_overrides(args, overrides)], stderr=subprocess.PIPE
221+
)
218222
_err = completed_process.stderr.decode()
219223
_status = completed_process.returncode
220224
if _status != 0:
221225
log.info("restarting dmypy from status: %s message: %s", _status, _err.strip())
222226
subprocess.run(["dmypy", "kill"])
223227

224228
# run to use existing daemon or restart if required
225-
args = ["run", "--"] + (apply_overrides(args, overrides) if overrides else args)
229+
args = ["run", "--"] + apply_overrides(args, overrides)
226230
log.info("dmypy run args = %s", args)
227231
completed_process = subprocess.run(
228232
["dmypy", *args], stdout=subprocess.PIPE, stderr=subprocess.PIPE

test/test_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pylsp import uris
66
from unittest.mock import Mock
77
from pylsp_mypy import plugin
8+
import collections
89

910
DOC_URI = __file__
1011
DOC_TYPE_ERR = """{}.append(3)
@@ -18,7 +19,7 @@
1819

1920
@pytest.fixture
2021
def diag_mp(monkeypatch):
21-
monkeypatch.setattr(plugin, "last_diagnostics", plugin.collections.defaultdict(list))
22+
monkeypatch.setattr(plugin, "last_diagnostics", collections.defaultdict(list))
2223
return monkeypatch
2324

2425

0 commit comments

Comments
 (0)