Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRY300: Add some extra notes on not catching exceptions you didn't expect #15036

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wlach
Copy link

@wlach wlach commented Dec 17, 2024

Summary

Added some extra notes on why you should have focused try...except blocks to TRY300.

When fixing a violation of this rule, a co-worker of mine (very understandably) asked why this was better. The current docs just say putting the return in the else is "more explicit", but if you look at the linked reference in the python documentation they are more clear on why violations like this is bad:

The use of the else clause is better than adding additional code to the try clause because it avoids accidentally catching an exception that wasn’t raised by the code being protected by the try … except statement.

This is my attempt at adding more context to the docs on this. Open to suggestions for wording!

Test Plan

N/A, just docs

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants