From df617c3093f518554de675da542f25a6cab85b16 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Fri, 19 Jan 2024 11:58:31 -0500 Subject: [PATCH] [`flake8-blind-except`] Document exceptions to `blind-except` rule (#9580) Closes https://github.com/astral-sh/ruff/issues/9571. --- .../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)