mirror of https://github.com/astral-sh/ruff
Avoid false-positives for break in with (#3032)
This commit is contained in:
parent
b75663be6d
commit
0f0e7a521a
|
|
@ -113,3 +113,14 @@ def test_break_in_if_orelse():
|
|||
else:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def test_break_in_with():
|
||||
"""no false positive for break in with"""
|
||||
for name in ["demo"]:
|
||||
with open(__file__) as f:
|
||||
if name in f.read():
|
||||
break
|
||||
else:
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ impl Violation for UselessElseOnLoop {
|
|||
fn loop_exits_early(body: &[Stmt]) -> bool {
|
||||
body.iter().any(|stmt| match &stmt.node {
|
||||
StmtKind::If { body, orelse, .. } => loop_exits_early(body) || loop_exits_early(orelse),
|
||||
StmtKind::With { body, .. } | StmtKind::AsyncWith { body, .. } => loop_exits_early(body),
|
||||
StmtKind::Try {
|
||||
body,
|
||||
handlers,
|
||||
|
|
|
|||
Loading…
Reference in New Issue