Skip to content

Commit

Permalink
[ruff] Issue astral-sh#9951, RUF029: skip the rest of traversal aft…
Browse files Browse the repository at this point in the history
…er finding an async/await (per @MichaReiser)
  • Loading branch information
plredmond committed Apr 16, 2024
1 parent f28fd87 commit 41f0ac5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/ruff_linter/src/rules/ruff/rules/spurious_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::identifier::Identifier;
use ruff_python_ast::visitor::preorder;
use ruff_python_ast::{self as ast, Expr, Stmt};
use ruff_python_ast::{self as ast, AnyNodeRef, Expr, Stmt};

use crate::checkers::ast::Checker;

Expand Down Expand Up @@ -45,6 +45,13 @@ struct AsyncExprVisitor {
}

impl<'a> preorder::PreorderVisitor<'a> for AsyncExprVisitor {
fn enter_node(&mut self, _node: AnyNodeRef<'a>) -> preorder::TraversalSignal {
if self.found_await_or_async {
preorder::TraversalSignal::Skip
} else {
preorder::TraversalSignal::Traverse
}
}
fn visit_expr(&mut self, expr: &'a Expr) {
match expr {
Expr::Await(_) => {
Expand Down

0 comments on commit 41f0ac5

Please sign in to comment.