[flake8-simplify] Improve help message clarity (SIM105)#20548
Merged
ntBre merged 2 commits intoastral-sh:mainfrom Sep 25, 2025
Merged
[flake8-simplify] Improve help message clarity (SIM105)#20548ntBre merged 2 commits intoastral-sh:mainfrom
flake8-simplify] Improve help message clarity (SIM105)#20548ntBre merged 2 commits intoastral-sh:mainfrom
Conversation
Improve the SIM105 rule message to prevent user confusion about how to
properly use `contextlib.suppress`.
The previous message "Replace with `contextlib.suppress(ValueError)`"
was ambiguous and led users to incorrectly use `contextlib.suppress(ValueError)`
as a statement inside except blocks instead of replacing the entire
try-except-pass block with `with contextlib.suppress(ValueError):`.
Changes:
- Update main message from "Use `contextlib.suppress({exception})` instead of `try`-`except`-`pass`"
to "Replace `try`-`except`-`pass` block with `with contextlib.suppress({exception})`"
- Update fix title from "Replace with `contextlib.suppress({exception})`"
to "Replace `try`-`except`-`pass` with `with contextlib.suppress({exception})`"
Fixes astral-sh#20462
ntBre
reviewed
Sep 24, 2025
Contributor
ntBre
left a comment
There was a problem hiding this comment.
Thank you! Just a couple of nits/ideas about the phrasing, but this looks great overall.
crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs
Outdated
Show resolved
Hide resolved
Address reviewer feedback by keeping the original main message and
only improving the fix_title to prevent user confusion.
The previous fix_title "Replace with `contextlib.suppress(ValueError)`"
was ambiguous and led users to incorrectly use `contextlib.suppress(ValueError)`
as a statement inside except blocks instead of replacing the entire
try-except-pass block.
Changes:
- Keep original main message: "Use `contextlib.suppress({exception})` instead of `try`-`except`-`pass`"
- Improve fix_title: "Replace `try`-`except`-`pass` with `with contextlib.suppress({exception}): ...`"
The new fix_title explicitly shows:
1. What to replace (the entire try-except-pass block)
2. The exact syntax needed (with statement)
3. Where code goes (indicated by ...)
Fixes astral-sh#20462
ntBre
approved these changes
Sep 25, 2025
Contributor
ntBre
left a comment
There was a problem hiding this comment.
This looks great, thank you!
flake8-simplify] Improve help message clarity (SIM105)
Contributor
|
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.
Summary
Improve the SIM105 rule message to prevent user confusion about how to properly use
contextlib.suppress.The previous message "Replace with
contextlib.suppress(ValueError)" was ambiguous and led users to incorrectly usecontextlib.suppress(ValueError)as a statement inside except blocks instead of replacing the entire try-except-pass block withwith contextlib.suppress(ValueError):.This change makes the message more explicit:
"Use \contextlib.suppress({exception})` instead of `try`-`except`-`pass`"`"Replace \try`-`except`-`pass` block with `with contextlib.suppress({exception})`"`The fix title is also updated to be more specific:
"Replace with \contextlib.suppress({exception})`"`"Replace \try`-`except`-`pass` with `with contextlib.suppress({exception})`"`Fixes #20462
Test Plan
withstatement, preventing the misuse described in the issue