Skip to content

Commit

Permalink
Fix false-positive for TRY302 if exception cause is given (#4559)
Browse files Browse the repository at this point in the history
  • Loading branch information
153957 authored May 21, 2023
1 parent 6db05d8 commit 8ca3977
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions crates/ruff/resources/test/fixtures/tryceratops/TRY302.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8ca3977

Please sign in to comment.