Skip to content

Commit ca57db8

Browse files
committed
Move exclude code to pylsp_lint so mypy is not invoked unnecessarily
1 parent 2f9d678 commit ca57db8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

pylsp_mypy/plugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ def pylsp_lint(
181181

182182
didSettingsChange(workspace.root_path, settings)
183183

184+
# Running mypy with a single file (document) ignores any exclude pattern
185+
# configured with mypy. We can now add our own exclude section like so:
186+
# [tool.pylsp-mypy]
187+
# exclude = ["tests/*"]
188+
exclude = settings.get("exclude", [])
189+
for pattern in exclude:
190+
if re.match(pattern, document.path):
191+
log.debug(
192+
f"Not running because {document.path} matches "
193+
f"exclude pattern '{pattern}'"
194+
)
195+
return []
196+
184197
if settings.get("report_progress", False):
185198
with workspace.report_progress("lint: mypy"):
186199
return get_diagnostics(workspace, document, settings, is_saved)
@@ -218,15 +231,6 @@ def get_diagnostics(
218231
document.path,
219232
is_saved,
220233
)
221-
exclude = settings.get("exclude", [])
222-
for pattern in exclude:
223-
if re.match(pattern, document.path):
224-
log.debug(
225-
"Not running because %s matches exclude pattern %s",
226-
document.path,
227-
settings.get("exclude"),
228-
)
229-
return []
230234

231235
live_mode = settings.get("live_mode", True)
232236
dmypy = settings.get("dmypy", False)

0 commit comments

Comments
 (0)