Skip to content

Commit

Permalink
Fix SIM113 false positive with async for loops (#9996)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
adrienball authored Feb 16, 2024
1 parent fe79798 commit c3bba54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,11 @@ def inner():
for y in range(5):
g(x, idx)
idx += 1

async def func():
# OK (for loop is async)
idx = 0

async for x in async_gen():
g(x, idx)
idx += 1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl Violation for EnumerateForLoop {

/// SIM113
pub(crate) fn enumerate_for_loop(checker: &mut Checker, for_stmt: &ast::StmtFor) {
// If the loop is async, abort.
if for_stmt.is_async {
return;
}

// If the loop contains a `continue`, abort.
let mut visitor = LoopControlFlowVisitor::default();
visitor.visit_body(&for_stmt.body);
Expand Down

0 comments on commit c3bba54

Please sign in to comment.