diff --git a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs index 8c58b2d5ad4d2..1139ae7e1275f 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs @@ -3,7 +3,6 @@ use std::fmt; use ast::Stmt; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::call_path::compose_call_path; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::{analyze::typing, Scope, SemanticModel}; use ruff_text_size::Ranged; @@ -93,22 +92,24 @@ pub(crate) fn asyncio_dangling_task(expr: &Expr, semantic: &SemanticModel) -> Op // Ex) `loop = ...; loop.create_task(...)` if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func.as_ref() { if attr == "create_task" { - if typing::resolve_assignment(value, semantic).is_some_and(|call_path| { - matches!( - call_path.as_slice(), - [ - "asyncio", - "get_event_loop" | "get_running_loop" | "new_event_loop" - ] - ) - }) { - return Some(Diagnostic::new( - AsyncioDanglingTask { - expr: compose_call_path(value).unwrap_or_else(|| "asyncio".to_string()), - method: Method::CreateTask, - }, - expr.range(), - )); + if let Expr::Name(name) = value.as_ref() { + if typing::resolve_assignment(value, semantic).is_some_and(|call_path| { + matches!( + call_path.as_slice(), + [ + "asyncio", + "get_event_loop" | "get_running_loop" | "new_event_loop" + ] + ) + }) { + return Some(Diagnostic::new( + AsyncioDanglingTask { + expr: name.id.to_string(), + method: Method::CreateTask, + }, + expr.range(), + )); + } } } }