Skip to content

Template Sync: Use contextlib.suppress instead of try-except-pass in lsp_utils.py #465

@github-actions

Description

@github-actions

🔄 Template Sync Required

Changes from the upstream vscode-python-tools-extension-template have not yet been incorporated into this repository.

Source PR

Summary

The template replaced bare try: ... except SomeException: pass patterns with the idiomatic contextlib.suppress(SomeException) context manager in bundled/tool/lsp_utils.py. This improves readability and avoids bare-except pylint warnings.

Files with missing changes

  • bundled/tool/lsp_utils.py: The _run_api function still uses the old try/except SystemExit: pass pattern.

    Note: _run_module's except SystemExit as ex: block was intentionally kept as-is since it captures exit_code = ex.code (mypy-specific behavior that cannot be replaced with suppress).

Suggested fix

--- a/bundled/tool/lsp_utils.py
+++ b/bundled/tool/lsp_utils.py
@@ -... @@
 def _run_api(...) -> RunResult:
     str_output = None
     str_error = None

-    try:
+    with contextlib.suppress(SystemExit):
         with substitute_attr(sys, "argv", argv):
             if use_stdin and source is not None:
                 str_input = CustomIO("(stdin)", encoding="utf-8", newline="\n")
                 with redirect_io("stdin", str_input):
                     str_input.write(source)
                     str_input.seek(0)
                     str_output, str_error, exit_code = callback(argv, str_input)
             else:
                 str_output, str_error, exit_code = callback(argv, None)
-    except SystemExit:
-        pass

     return RunResult(str_output, str_error, exit_code)

You will also need to ensure import contextlib is present at the top of lsp_utils.py (it is already imported for change_cwd).

Files skipped

  • bundled/tool/lsp_jsonrpc.py: This file does not exist in this repository (the template's lsp_jsonrpc.py changes are not applicable here).

🤖 This issue was auto-generated by the extension-template-sync workflow.

Generated by Extension Template Sync

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions