@@ -207,6 +207,7 @@ def pylsp_lint(
207207 args .append ("--strict" )
208208
209209 overrides = settings .get ("overrides" , [True ])
210+ exit_status = 0
210211
211212 if not dmypy :
212213 args .extend (["--incremental" , "--follow-imports" , "silent" ])
@@ -221,11 +222,12 @@ def pylsp_lint(
221222 )
222223 report = completed_process .stdout .decode ()
223224 errors = completed_process .stderr .decode ()
225+ exit_status = completed_process .returncode
224226 else :
225227 # mypy does not exist on path, but must exist in the env pylsp-mypy is installed in
226228 # -> use mypy via api
227229 log .info ("executing mypy args = %s via api" , args )
228- report , errors , _ = mypy_api .run (args )
230+ report , errors , exit_status = mypy_api .run (args )
229231 else :
230232 # If dmypy daemon is non-responsive calls to run will block.
231233 # Check daemon status, if non-zero daemon is dead or hung.
@@ -239,20 +241,20 @@ def pylsp_lint(
239241 completed_process = subprocess .run (
240242 ["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE , ** windows_flag
241243 )
242- _err = completed_process .stderr .decode ()
243- _status = completed_process .returncode
244- if _status != 0 :
244+ errors = completed_process .stderr .decode ()
245+ exit_status = completed_process .returncode
246+ if exit_status != 0 :
245247 log .info (
246- "restarting dmypy from status: %s message: %s via path" , _status , _err .strip ()
248+ "restarting dmypy from status: %s message: %s via path" , exit_status , errors .strip ()
247249 )
248250 subprocess .run (["dmypy" , "kill" ], ** windows_flag )
249251 else :
250252 # dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
251253 # -> use dmypy via api
252- _ , _err , _status = mypy_api .run_dmypy (["status" ])
253- if _status != 0 :
254+ _ , errors , exit_status = mypy_api .run_dmypy (["status" ])
255+ if exit_status != 0 :
254256 log .info (
255- "restarting dmypy from status: %s message: %s via api" , _status , _err .strip ()
257+ "restarting dmypy from status: %s message: %s via api" , exit_status , errors .strip ()
256258 )
257259 mypy_api .run_dmypy (["kill" ])
258260
@@ -268,11 +270,12 @@ def pylsp_lint(
268270 )
269271 report = completed_process .stdout .decode ()
270272 errors = completed_process .stderr .decode ()
273+ exit_status = completed_process .returncode
271274 else :
272275 # dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
273276 # -> use dmypy via api
274277 log .info ("dmypy run args = %s via api" , args )
275- report , errors , _ = mypy_api .run_dmypy (args )
278+ report , errors , exit_status = mypy_api .run_dmypy (args )
276279
277280 log .debug ("report:\n %s" , report )
278281 log .debug ("errors:\n %s" , errors )
@@ -290,7 +293,7 @@ def pylsp_lint(
290293 "end" : {"line" : 0 , "character" : 1000 },
291294 },
292295 "message" : errors ,
293- "severity" : 1 , # Error
296+ "severity" : 1 if exit_status != 0 else 2 , # Error if exited with error or warning.
294297 }
295298 )
296299
0 commit comments