mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
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.
This commit is contained in:
parent
fe79798c12
commit
c3bba54b6b
2 changed files with 13 additions and 0 deletions
|
@ -193,3 +193,11 @@ def func():
|
|||
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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue