diff --git a/crates/ruff/resources/test/fixtures/tryceratops/TRY302.py b/crates/ruff/resources/test/fixtures/tryceratops/TRY302.py index 0020926e4d2f3..3691e5472afc5 100644 --- a/crates/ruff/resources/test/fixtures/tryceratops/TRY302.py +++ b/crates/ruff/resources/test/fixtures/tryceratops/TRY302.py @@ -68,6 +68,18 @@ def bad(): except Exception as e: raise e +def fine(): + try: + process() + except Exception as e: + raise e from None + +def fine(): + try: + process() + except Exception as e: + raise e from Exception + def fine(): try: process() diff --git a/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs b/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs index e2446ddc6d679..8869e4eccdc26 100644 --- a/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs +++ b/crates/ruff/src/rules/tryceratops/rules/useless_try_except.rs @@ -44,7 +44,7 @@ pub(crate) fn useless_try_except(checker: &mut Checker, handlers: &[Excepthandle .iter() .map(|handler| { let ExceptHandler(ExcepthandlerExceptHandler { name, body, .. }) = handler; - let Some(Stmt::Raise(ast::StmtRaise { exc, .. })) = &body.first() else { + let Some(Stmt::Raise(ast::StmtRaise { exc, cause: None, .. })) = &body.first() else { return None; }; if let Some(expr) = exc {