From 625d4625acae7325e172a0a6e5678289e22f5ccd Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 19 Jan 2024 11:44:21 -0500 Subject: [PATCH] Document exceptions to blind-except rule --- .../flake8_blind_except/rules/blind_except.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs index 102f40be9913e..3eab03f29ab42 100644 --- a/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs +++ b/crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs @@ -34,6 +34,25 @@ use crate::checkers::ast::Checker; /// ... /// ``` /// +/// Exceptions that are re-raised will _not_ be flagged, as they're expected to +/// be caught elsewhere: +/// ```python +/// try: +/// foo() +/// except BaseException: +/// raise +/// ``` +/// +/// Exceptions that are logged via `logging.exception()` or `logging.error()` +/// with `exc_info` enabled will _not_ be flagged, as this is a common pattern +/// for propagating exception traces: +/// ```python +/// try: +/// foo() +/// except BaseException: +/// logging.exception("Something went wrong") +/// ``` +/// /// ## References /// - [Python documentation: The `try` statement](https://docs.python.org/3/reference/compound_stmts.html#the-try-statement) /// - [Python documentation: Exception hierarchy](https://docs.python.org/3/library/exceptions.html#exception-hierarchy)