4242# https://github.com/python-lsp/python-lsp-server/blob/v1.0.1/pylsp/plugins/pylint_lint.py#L55-L62
4343last_diagnostics : Dict [str , List [Dict [str , Any ]]] = collections .defaultdict (list )
4444
45+ # Windows started opening opening a cmd-like window for every subprocess call
46+ # This flag prevents that.
47+ # This flag is new in python 3.7
48+ # THis flag only exists on Windows
49+ windows_flag : Dict [str , int ] = (
50+ {"startupinfo" : subprocess .CREATE_NO_WINDOW } if os .name == "nt" else {} # type: ignore
51+ )
52+
4553
4654def parse_line (line : str , document : Optional [Document ] = None ) -> Optional [Dict [str , Any ]]:
4755 """
@@ -214,7 +222,7 @@ def pylsp_lint(
214222 # -> use mypy on path
215223 log .info ("executing mypy args = %s on path" , args )
216224 completed_process = subprocess .run (
217- ["mypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
225+ ["mypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** windows_flag
218226 )
219227 report = completed_process .stdout .decode ()
220228 errors = completed_process .stderr .decode ()
@@ -234,15 +242,15 @@ def pylsp_lint(
234242 # dmypy exists on path
235243 # -> use mypy on path
236244 completed_process = subprocess .run (
237- ["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE
245+ ["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE , ** windows_flag
238246 )
239247 _err = completed_process .stderr .decode ()
240248 _status = completed_process .returncode
241249 if _status != 0 :
242250 log .info (
243251 "restarting dmypy from status: %s message: %s via path" , _status , _err .strip ()
244252 )
245- subprocess .run (["dmypy" , "kill" ])
253+ subprocess .run (["dmypy" , "kill" ], ** windows_flag )
246254 else :
247255 # dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
248256 # -> use dmypy via api
@@ -261,7 +269,7 @@ def pylsp_lint(
261269 # -> use mypy on path
262270 log .info ("dmypy run args = %s via path" , args )
263271 completed_process = subprocess .run (
264- ["dmypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
272+ ["dmypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** windows_flag
265273 )
266274 report = completed_process .stdout .decode ()
267275 errors = completed_process .stderr .decode ()
0 commit comments