mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:54:42 +00:00
[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.
This commit is contained in:
parent
e3fde28146
commit
cee38f39df
2 changed files with 17 additions and 5 deletions
|
@ -124,3 +124,8 @@ try:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
error("...", exc_info=True)
|
error("...", exc_info=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
...
|
||||||
|
except Exception as e:
|
||||||
|
raise ValueError from e
|
||||||
|
|
|
@ -87,18 +87,25 @@ pub(crate) fn blind_except(
|
||||||
if !matches!(builtin_exception_type, "BaseException" | "Exception") {
|
if !matches!(builtin_exception_type, "BaseException" | "Exception") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the exception is re-raised, don't flag an error.
|
// If the exception is re-raised, don't flag an error.
|
||||||
if body.iter().any(|stmt| {
|
if body.iter().any(|stmt| {
|
||||||
if let Stmt::Raise(ast::StmtRaise { exc, .. }) = stmt {
|
if let Stmt::Raise(ast::StmtRaise { exc, cause, .. }) = stmt {
|
||||||
if let Some(exc) = exc {
|
if let Some(cause) = cause {
|
||||||
if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() {
|
if let Expr::Name(ast::ExprName { id, .. }) = cause.as_ref() {
|
||||||
name.is_some_and(|name| id == name)
|
name.is_some_and(|name| id == name)
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
true
|
if let Some(exc) = exc {
|
||||||
|
if let Expr::Name(ast::ExprName { id, .. }) = exc.as_ref() {
|
||||||
|
name.is_some_and(|name| id == name)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue