diff --git a/bundled/tool/lsp_jsonrpc.py b/bundled/tool/lsp_jsonrpc.py index a0a5ad5..011b511 100644 --- a/bundled/tool/lsp_jsonrpc.py +++ b/bundled/tool/lsp_jsonrpc.py @@ -4,6 +4,7 @@ import atexit +import contextlib import io import json import pathlib @@ -99,14 +100,10 @@ def __init__(self, reader: io.TextIOWrapper, writer: io.TextIOWrapper): def close(self): """Closes the underlying streams.""" - try: + with contextlib.suppress(Exception): self._reader.close() - except: # pylint: disable=bare-except - pass - try: + with contextlib.suppress(Exception): self._writer.close() - except: # pylint: disable=bare-except - pass def send_data(self, data): """Send given data in JSON-RPC format.""" @@ -135,10 +132,8 @@ def __init__(self): def stop_all_processes(self): """Send exit command to all processes and shutdown transport.""" for i in self._rpc.values(): - try: + with contextlib.suppress(Exception): i.send_data({"id": str(uuid.uuid4()), "method": "exit"}) - except: # pylint: disable=bare-except - pass self._thread_pool.shutdown(wait=False) def start_process(self, workspace: str, args: Sequence[str], cwd: str) -> None: diff --git a/bundled/tool/lsp_utils.py b/bundled/tool/lsp_utils.py index a7885bc..fb5f032 100644 --- a/bundled/tool/lsp_utils.py +++ b/bundled/tool/lsp_utils.py @@ -114,7 +114,7 @@ def _run_module( str_output = CustomIO("", encoding="utf-8") str_error = CustomIO("", encoding="utf-8") - try: + with contextlib.suppress(SystemExit): with substitute_attr(sys, "argv", argv): with redirect_io("stdout", str_output): with redirect_io("stderr", str_error): @@ -126,8 +126,6 @@ def _run_module( runpy.run_module(module, run_name="__main__") else: runpy.run_module(module, run_name="__main__") - except SystemExit: - pass return RunResult(str_output.get_value(), str_error.get_value()) @@ -193,7 +191,7 @@ def _run_api( str_output = CustomIO("", encoding="utf-8") str_error = CustomIO("", encoding="utf-8") - try: + with contextlib.suppress(SystemExit): with substitute_attr(sys, "argv", argv): with redirect_io("stdout", str_output): with redirect_io("stderr", str_error): @@ -205,7 +203,5 @@ def _run_api( callback(argv, str_output, str_error, str_input) else: callback(argv, str_output, str_error) - except SystemExit: - pass return RunResult(str_output.get_value(), str_error.get_value())