mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
![]() ## Summary Added some extra notes on why you should have focused try...except blocks to [TRY300](https://docs.astral.sh/ruff/rules/try-consider-else/). 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](https://docs.python.org/3/tutorial/errors.html) 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](https://docs.python.org/3/reference/compound_stmts.html#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! --------- Co-authored-by: dylwil3 <dylwil3@gmail.com> |
||
---|---|---|
.. | ||
checkers | ||
comments | ||
cst | ||
docstrings | ||
fix | ||
importer | ||
message | ||
registry | ||
rules | ||
settings | ||
snapshots | ||
codes.rs | ||
directives.rs | ||
doc_lines.rs | ||
fs.rs | ||
lib.rs | ||
line_width.rs | ||
linter.rs | ||
locator.rs | ||
logging.rs | ||
noqa.rs | ||
package.rs | ||
packaging.rs | ||
pyproject_toml.rs | ||
registry.rs | ||
renamer.rs | ||
rule_redirects.rs | ||
rule_selector.rs | ||
source_kind.rs | ||
test.rs | ||
text_helpers.rs | ||
upstream_categories.rs |