Skip to content

Commit

Permalink
recursively search for yield
Browse files Browse the repository at this point in the history
  • Loading branch information
dylwil3 committed Aug 14, 2024
1 parent 8630f82 commit 8f424b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ async def foo():
with trio.fail_after(1):
yield

async def foo(): # even if only one branch contains a yield, we skip the lint
with trio.fail_after(1):
if something:
...
else:
yield

# https://github.com/astral-sh/ruff/issues/12873
@asynccontextmanager
async def good_code():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::AwaitVisitor;
use ruff_python_ast::helpers::{any_over_body, AwaitVisitor};
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{StmtWith, WithItem};
use ruff_python_ast::{Expr, StmtWith, WithItem};

use crate::checkers::ast::Checker;
use crate::rules::flake8_async::helpers::MethodName;
Expand Down Expand Up @@ -87,10 +87,7 @@ pub(crate) fn cancel_scope_no_checkpoint(
// in the caller yielded to.
// https://flake8-async.readthedocs.io/en/latest/rules.html#async100
// https://github.com/astral-sh/ruff/issues/12873
if with_stmt.body.iter().any(|stmt| {
stmt.as_expr_stmt()
.is_some_and(|expr| expr.value.is_yield_expr())
}) {
if any_over_body(&with_stmt.body, &Expr::is_yield_expr) {
return;
}

Expand Down

0 comments on commit 8f424b3

Please sign in to comment.