Skip to content

Commit cee38f3

Browse files
authored
[flake8-blind-expect] Allow raise from in BLE001 (#11131)
## Summary This allows `raise from` in BLE001. ```python try: ... except Exception as e: raise ValueError from e ``` Fixes #10806 ## Test Plan Test case added.
1 parent e3fde28 commit cee38f3

File tree

2 files changed

+17
-5
lines changed
  • crates/ruff_linter

2 files changed

+17
-5
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_blind_except/BLE.py

+5
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,8 @@
124124
pass
125125
except Exception:
126126
error("...", exc_info=True)
127+
128+
try:
129+
...
130+
except Exception as e:
131+
raise ValueError from e

crates/ruff_linter/src/rules/flake8_blind_except/rules/blind_except.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,25 @@ pub(crate) fn blind_except(
8787
if !matches!(builtin_exception_type, "BaseException" | "Exception") {
8888
return;
8989
}
90-
9190
// If the exception is re-raised, don't flag an error.
9291
if body.iter().any(|stmt| {
93-
if let Stmt::Raise(ast::StmtRaise { exc, .. }) = stmt {
94-
if let Some(exc) = exc {
95-
if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() {
92+
if let Stmt::Raise(ast::StmtRaise { exc, cause, .. }) = stmt {
93+
if let Some(cause) = cause {
94+
if let Expr::Name(ast::ExprName { id, .. }) = cause.as_ref() {
9695
name.is_some_and(|name| id == name)
9796
} else {
9897
false
9998
}
10099
} else {
101-
true
100+
if let Some(exc) = exc {
101+
if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() {
102+
name.is_some_and(|name| id == name)
103+
} else {
104+
false
105+
}
106+
} else {
107+
true
108+
}
102109
}
103110
} else {
104111
false

0 commit comments

Comments
 (0)