mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:49:50 +00:00
Omit while-True loops from implicit return enforcement (#3076)
This commit is contained in:
parent
35f7f7b66d
commit
7d4e513a82
2 changed files with 24 additions and 9 deletions
|
@ -77,7 +77,7 @@ def x(y):
|
|||
|
||||
# last line in while loop
|
||||
def x(y):
|
||||
while True:
|
||||
while i > 0:
|
||||
if y > 0:
|
||||
return 1
|
||||
y += 1
|
||||
|
@ -259,3 +259,10 @@ def nested(values):
|
|||
|
||||
for value in values:
|
||||
print(value)
|
||||
|
||||
|
||||
def while_true():
|
||||
while True:
|
||||
if y > 0:
|
||||
return 1
|
||||
y += 1
|
||||
|
|
|
@ -220,6 +220,22 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
checker.diagnostics.push(diagnostic);
|
||||
}
|
||||
}
|
||||
StmtKind::Assert { test, .. }
|
||||
if matches!(
|
||||
test.node,
|
||||
ExprKind::Constant {
|
||||
value: Constant::Bool(false),
|
||||
..
|
||||
}
|
||||
) => {}
|
||||
StmtKind::While { test, .. }
|
||||
if matches!(
|
||||
test.node,
|
||||
ExprKind::Constant {
|
||||
value: Constant::Bool(true),
|
||||
..
|
||||
}
|
||||
) => {}
|
||||
StmtKind::For { orelse, .. }
|
||||
| StmtKind::AsyncFor { orelse, .. }
|
||||
| StmtKind::While { orelse, .. } => {
|
||||
|
@ -244,14 +260,6 @@ fn implicit_return(checker: &mut Checker, stmt: &Stmt) {
|
|||
implicit_return(checker, last_stmt);
|
||||
}
|
||||
}
|
||||
StmtKind::Assert { test, .. }
|
||||
if matches!(
|
||||
test.node,
|
||||
ExprKind::Constant {
|
||||
value: Constant::Bool(false),
|
||||
..
|
||||
}
|
||||
) => {}
|
||||
StmtKind::Return { .. } | StmtKind::Raise { .. } | StmtKind::Try { .. } => {}
|
||||
StmtKind::Expr { value, .. }
|
||||
if matches!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue