Skip to content

Commit c3bba54

Browse files
authored
Fix SIM113 false positive with async for loops (#9996)
## Summary Ignore `async for` loops when checking the SIM113 rule. Closes #9995 ## Test Plan A new test case was added to SIM113.py with an async for loop.
1 parent fe79798 commit c3bba54

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM113.py

+8
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,11 @@ def inner():
193193
for y in range(5):
194194
g(x, idx)
195195
idx += 1
196+
197+
async def func():
198+
# OK (for loop is async)
199+
idx = 0
200+
201+
async for x in async_gen():
202+
g(x, idx)
203+
idx += 1

crates/ruff_linter/src/rules/flake8_simplify/rules/enumerate_for_loop.rs

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ impl Violation for EnumerateForLoop {
4949

5050
/// SIM113
5151
pub(crate) fn enumerate_for_loop(checker: &mut Checker, for_stmt: &ast::StmtFor) {
52+
// If the loop is async, abort.
53+
if for_stmt.is_async {
54+
return;
55+
}
56+
5257
// If the loop contains a `continue`, abort.
5358
let mut visitor = LoopControlFlowVisitor::default();
5459
visitor.visit_body(&for_stmt.body);

0 commit comments

Comments
 (0)