Replace try-except-pass with contextlib.suppress#428
Merged
Conversation
- lsp_jsonrpc.py: Add import contextlib, replace 3 try/except:pass with contextlib.suppress(Exception) - lsp_utils.py: Replace 2 try/except SystemExit:pass with contextlib.suppress(SystemExit) Co-authored-by: edvilme <[email protected]>
Co-authored-by: edvilme <[email protected]>
Copilot
AI
changed the title
[WIP] Update lsp_jsonrpc.py to use contextlib.suppress
Replace try-except-pass with contextlib.suppress
Mar 4, 2026
StellaHuang95
approved these changes
Mar 4, 2026
rchiodo
approved these changes
Mar 4, 2026
Contributor
rchiodo
left a comment
There was a problem hiding this comment.
Approved via Review Center.
This was referenced Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sync with upstream template (microsoft/vscode-python-tools-extension-template#204): replace bare
try/except: passblocks withcontextlib.suppress(...).bundled/tool/lsp_jsonrpc.py— Addimport contextlib; replace 3 bareexcept/passblocks inJsonRpc.close()andProcessManager.stop_all_processes()withcontextlib.suppress(Exception)bundled/tool/lsp_utils.py— Replace 2except SystemExit: passblocks in_run_module()and_run_api()withcontextlib.suppress(SystemExit)Original prompt
This section details on the original issue you should resolve
<issue_title>Template Sync: Use
contextlib.suppressinstead of try-except-pass</issue_title><issue_description>### 🔄 Template Sync Required
Changes from the upstream vscode-python-tools-extension-template have not yet been incorporated into this repository.
Source PR
contextlib.suppressinstead of try-except-passSummary
The template replaced bare
try/except: passblocks (which silence all exceptions without logging) withcontextlib.suppress(...), a more idiomatic and explicit Python pattern. This applies to stream-close operations inlsp_jsonrpc.pyandSystemExithandling inlsp_utils.py.Files with missing changes
bundled/tool/lsp_jsonrpc.py— Three locations still usetry/except: passthat should be replaced withcontextlib.suppress(Exception). Also missingimport contextlibat the top.bundled/tool/lsp_utils.py— Two locations in_run_moduleand_run_apistill usetry/except SystemExit: passthat should be replaced withcontextlib.suppress(SystemExit)(contextlib is already imported here).Suggested fix
bundled/tool/lsp_jsonrpc.py— addimport contextliband update three locations:bundled/tool/lsp_utils.py— update_run_module(around line 172) and_run_api(around line 251):Files skipped
None — both files are shared template infrastructure files.
🤖 This issue was auto-generated by the
extension-template-syncworkflow.Comments on the Issue (you are @copilot in this section)
contextlib.suppressinstead of try-except-pass #423✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.