Skip to content

Commit

Permalink
update rule
Browse files Browse the repository at this point in the history
  • Loading branch information
dylwil3 committed Aug 14, 2024
1 parent 664e645 commit 8630f82
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::rules::flake8_async::helpers::MethodName;
/// ## What it does
/// Checks for timeout context managers which do not contain a checkpoint.
///
/// For the purposes of this check, `yield` is considered a checkpoint,
/// since checkpoints may occur in the caller to which we yield.
///
/// ## Why is this bad?
/// Some asynchronous context managers, such as `asyncio.timeout` and
/// `trio.move_on_after`, have no effect unless they contain a checkpoint.
Expand Down Expand Up @@ -80,6 +83,17 @@ pub(crate) fn cancel_scope_no_checkpoint(
return;
}

// Treat yields as checkpoints, since checkpoints can happen
// 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())
}) {
return;
}

// If the body contains an `await` statement, the context manager is used correctly.
let mut visitor = AwaitVisitor::default();
visitor.visit_body(&with_stmt.body);
Expand Down

0 comments on commit 8630f82

Please sign in to comment.