Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[flake8-simplify] Improve help message clarity (SIM105)#20548

Merged
ntBre merged 2 commits intoastral-sh:mainfrom
mgiovani:fix/20462-improve-sim105-message
Sep 25, 2025
Merged

[flake8-simplify] Improve help message clarity (SIM105)#20548
ntBre merged 2 commits intoastral-sh:mainfrom
mgiovani:fix/20462-improve-sim105-message

Conversation

@mgiovani
Copy link
Contributor

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 use contextlib.suppress(ValueError) as a statement inside except blocks instead of replacing the entire try-except-pass block with with contextlib.suppress(ValueError):.

This change makes the message more explicit:

  • Before: "Use \contextlib.suppress({exception})` instead of `try`-`except`-`pass`"`
  • After: "Replace \try`-`except`-`pass` block with `with contextlib.suppress({exception})`"`

The fix title is also updated to be more specific:

  • Before: "Replace with \contextlib.suppress({exception})`"`
  • After: "Replace \try`-`except`-`pass` with `with contextlib.suppress({exception})`"`

Fixes #20462

Test Plan

  • ✅ All existing SIM105 tests pass with updated snapshots
  • ✅ Cargo clippy passes without warnings
  • ✅ Full test suite passes
  • ✅ The new messages clearly indicate that the entire try-except-pass block should be replaced with a with statement, preventing the misuse described in the issue

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
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Just a couple of nits/ideas about the phrasing, but this looks great overall.

@ntBre ntBre added the diagnostics Related to reporting of diagnostics. label Sep 24, 2025
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
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thank you!

@ntBre ntBre changed the title [flake8-simplify] Improve SIM105 message clarity (SIM105) [flake8-simplify] Improve help message clarity (SIM105) Sep 25, 2025
@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@ntBre ntBre merged commit beec2f2 into astral-sh:main Sep 25, 2025
36 checks passed
@mgiovani mgiovani deleted the fix/20462-improve-sim105-message branch September 25, 2025 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: Improve SIM105 message, check for improper use of contextlib.suppress

2 participants