Skip to content

Commit cbe87e9

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

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

pylsp_mypy/plugin.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,18 @@ 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 " f"exclude pattern '{pattern}'"
193+
)
194+
return []
195+
184196
if settings.get("report_progress", False):
185197
with workspace.report_progress("lint: mypy"):
186198
return get_diagnostics(workspace, document, settings, is_saved)
@@ -218,15 +230,6 @@ def get_diagnostics(
218230
document.path,
219231
is_saved,
220232
)
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 []
230233

231234
live_mode = settings.get("live_mode", True)
232235
dmypy = settings.get("dmypy", False)

0 commit comments

Comments
 (0)