@@ -207,6 +207,7 @@ def pylsp_lint(
207
207
args .append ("--strict" )
208
208
209
209
overrides = settings .get ("overrides" , [True ])
210
+ exit_status = 0
210
211
211
212
if not dmypy :
212
213
args .extend (["--incremental" , "--follow-imports" , "silent" ])
@@ -221,11 +222,12 @@ def pylsp_lint(
221
222
)
222
223
report = completed_process .stdout .decode ()
223
224
errors = completed_process .stderr .decode ()
225
+ exit_status = completed_process .returncode
224
226
else :
225
227
# mypy does not exist on path, but must exist in the env pylsp-mypy is installed in
226
228
# -> use mypy via api
227
229
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 )
229
231
else :
230
232
# If dmypy daemon is non-responsive calls to run will block.
231
233
# Check daemon status, if non-zero daemon is dead or hung.
@@ -239,20 +241,20 @@ def pylsp_lint(
239
241
completed_process = subprocess .run (
240
242
["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE , ** windows_flag
241
243
)
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 :
245
247
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 ()
247
249
)
248
250
subprocess .run (["dmypy" , "kill" ], ** windows_flag )
249
251
else :
250
252
# dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
251
253
# -> 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 :
254
256
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 ()
256
258
)
257
259
mypy_api .run_dmypy (["kill" ])
258
260
@@ -268,11 +270,12 @@ def pylsp_lint(
268
270
)
269
271
report = completed_process .stdout .decode ()
270
272
errors = completed_process .stderr .decode ()
273
+ exit_status = completed_process .returncode
271
274
else :
272
275
# dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
273
276
# -> use dmypy via api
274
277
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 )
276
279
277
280
log .debug ("report:\n %s" , report )
278
281
log .debug ("errors:\n %s" , errors )
@@ -290,7 +293,7 @@ def pylsp_lint(
290
293
"end" : {"line" : 0 , "character" : 1000 },
291
294
},
292
295
"message" : errors ,
293
- "severity" : 1 , # Error
296
+ "severity" : 1 if exit_status != 0 else 2 , # Error if exited with error or warning.
294
297
}
295
298
)
296
299
0 commit comments