ruff/crates/ruff_linter/src
Will Lachance 38adc7f702
TRY300: Add some extra notes on not catching exceptions you didn't expect (#15036)
## 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>
2025-01-18 10:23:43 -06:00
..
checkers [pylint] Implement redefined-slots-in-subclass (W0244) (#9640) 2025-01-17 09:54:15 -06:00
comments Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
cst Wrap expressions in parentheses when negating (#10346) 2024-03-11 18:20:55 -04:00
docstrings Upgrade Rust toolchain to 1.84.0 (#15408) 2025-01-11 09:51:58 +01:00
fix Upgrade Rust toolchain to 1.84.0 (#15408) 2025-01-11 09:51:58 +01:00
importer Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
message ruff_linter: adjust empty spans after line terminator more generally 2025-01-15 13:37:52 -05:00
registry Increase rule set size (#14689) 2024-11-30 15:12:10 +01:00
rules TRY300: Add some extra notes on not catching exceptions you didn't expect (#15036) 2025-01-18 10:23:43 -06:00
settings [pydoclint] Allow ignoring one line docstrings for DOC rules (#13302) 2025-01-16 16:05:10 -06:00
snapshots test: another line terminator bug fix 2025-01-15 13:37:52 -05:00
codes.rs [pylint] Implement redefined-slots-in-subclass (W0244) (#9640) 2025-01-17 09:54:15 -06:00
directives.rs Use bitshift consistently for bitflag definitions (#14265) 2024-11-11 10:20:17 +00:00
doc_lines.rs Extract LineIndex independent methods from Locator (#13938) 2024-10-28 07:53:41 +00:00
fs.rs Struct not tuple for compiled per-file ignores (#10864) 2024-04-11 13:47:57 -06:00
lib.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
line_width.rs Upgrade to Rust 1.78 (#11260) 2024-05-03 12:46:21 +00:00
linter.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
locator.rs test: another update to add back a caret 2025-01-15 13:37:52 -05:00
logging.rs Bump MSRV to Rust 1.80 (#13826) 2024-10-20 10:55:36 +02:00
noqa.rs Upgrade Rust toolchain to 1.84.0 (#15408) 2025-01-11 09:51:58 +01:00
package.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
packaging.rs Nested namespace packages support (#10541) 2024-03-24 22:53:32 -04:00
pyproject_toml.rs Update pyproject-toml to 0.8 (#8351) 2023-10-30 10:05:37 +00:00
registry.rs [flake8-builtins] Rename A005 and improve its error message (#15348) 2025-01-08 12:38:34 +00:00
renamer.rs [ruff] Implement falsy-dict-get-fallback (RUF056) (#15160) 2024-12-31 11:40:51 +01:00
rule_redirects.rs Add a test for overshadowing redirects (#15259) 2025-01-05 09:47:01 +01:00
rule_selector.rs Added ignoring deprecated rules for --select=ALL (#10497) 2024-06-27 13:44:11 +02:00
source_kind.rs Simplify iteration idioms (#13834) 2024-10-20 22:25:27 +01:00
test.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
text_helpers.rs Handle non-printable characters in diff view (#11687) 2024-06-08 06:22:03 +00:00
upstream_categories.rs Fix pylint upstream categories not showing in docs (#10441) 2024-03-18 01:27:39 +00:00