mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 22:10:48 -05:00
@@ -25,6 +25,7 @@ fn return_values<'a>(stmt: &'a Stmt, sibling: &'a Stmt) -> Option<Loop<'a>> {
|
||||
body,
|
||||
target,
|
||||
iter,
|
||||
orelse,
|
||||
..
|
||||
} = &stmt.node else {
|
||||
return None;
|
||||
@@ -35,16 +36,23 @@ fn return_values<'a>(stmt: &'a Stmt, sibling: &'a Stmt) -> Option<Loop<'a>> {
|
||||
if body.len() != 1 {
|
||||
return None;
|
||||
}
|
||||
// TODO(charlie): If we have `else: return True` or `else: return False`, we
|
||||
// should still be able to simplify.
|
||||
if !orelse.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let StmtKind::If {
|
||||
body: nested_body,
|
||||
test: nested_test,
|
||||
..
|
||||
test: nested_test, orelse: nested_orelse,
|
||||
} = &body[0].node else {
|
||||
return None;
|
||||
};
|
||||
if nested_body.len() != 1 {
|
||||
return None;
|
||||
}
|
||||
if !nested_orelse.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let StmtKind::Return { value } = &nested_body[0].node else {
|
||||
return None;
|
||||
};
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
---
|
||||
source: src/flake8_simplify/mod.rs
|
||||
expression: checks
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ConvertLoopToAny: return any(check(x) for x in iterable)
|
||||
location:
|
||||
row: 2
|
||||
row: 3
|
||||
column: 4
|
||||
end_location:
|
||||
row: 4
|
||||
row: 5
|
||||
column: 23
|
||||
fix:
|
||||
content: return any(check(x) for x in iterable)
|
||||
location:
|
||||
row: 2
|
||||
row: 3
|
||||
column: 4
|
||||
end_location:
|
||||
row: 5
|
||||
row: 6
|
||||
column: 16
|
||||
parent: ~
|
||||
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
---
|
||||
source: src/flake8_simplify/mod.rs
|
||||
expression: checks
|
||||
expression: diagnostics
|
||||
---
|
||||
- kind:
|
||||
ConvertLoopToAll: return all(not check(x) for x in iterable)
|
||||
location:
|
||||
row: 16
|
||||
row: 25
|
||||
column: 4
|
||||
end_location:
|
||||
row: 18
|
||||
row: 27
|
||||
column: 24
|
||||
fix:
|
||||
content: return all(not check(x) for x in iterable)
|
||||
location:
|
||||
row: 16
|
||||
row: 25
|
||||
column: 4
|
||||
end_location:
|
||||
row: 19
|
||||
row: 28
|
||||
column: 15
|
||||
parent: ~
|
||||
- kind:
|
||||
ConvertLoopToAll: return all(x.is_empty() for x in iterable)
|
||||
location:
|
||||
row: 23
|
||||
row: 33
|
||||
column: 4
|
||||
end_location:
|
||||
row: 25
|
||||
row: 35
|
||||
column: 24
|
||||
fix:
|
||||
content: return all(x.is_empty() for x in iterable)
|
||||
location:
|
||||
row: 23
|
||||
row: 33
|
||||
column: 4
|
||||
end_location:
|
||||
row: 26
|
||||
row: 36
|
||||
column: 15
|
||||
parent: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user