Skip to content

Commit f40e012

Browse files
Use name directly in RUF006 (#9979)
1 parent 3e9d761 commit f40e012

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

crates/ruff_linter/src/rules/ruff/rules/asyncio_dangling_task.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::fmt;
33
use ast::Stmt;
44
use ruff_diagnostics::{Diagnostic, Violation};
55
use ruff_macros::{derive_message_formats, violation};
6-
use ruff_python_ast::call_path::compose_call_path;
76
use ruff_python_ast::{self as ast, Expr};
87
use ruff_python_semantic::{analyze::typing, Scope, SemanticModel};
98
use ruff_text_size::Ranged;
@@ -93,22 +92,24 @@ pub(crate) fn asyncio_dangling_task(expr: &Expr, semantic: &SemanticModel) -> Op
9392
// Ex) `loop = ...; loop.create_task(...)`
9493
if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func.as_ref() {
9594
if attr == "create_task" {
96-
if typing::resolve_assignment(value, semantic).is_some_and(|call_path| {
97-
matches!(
98-
call_path.as_slice(),
99-
[
100-
"asyncio",
101-
"get_event_loop" | "get_running_loop" | "new_event_loop"
102-
]
103-
)
104-
}) {
105-
return Some(Diagnostic::new(
106-
AsyncioDanglingTask {
107-
expr: compose_call_path(value).unwrap_or_else(|| "asyncio".to_string()),
108-
method: Method::CreateTask,
109-
},
110-
expr.range(),
111-
));
95+
if let Expr::Name(name) = value.as_ref() {
96+
if typing::resolve_assignment(value, semantic).is_some_and(|call_path| {
97+
matches!(
98+
call_path.as_slice(),
99+
[
100+
"asyncio",
101+
"get_event_loop" | "get_running_loop" | "new_event_loop"
102+
]
103+
)
104+
}) {
105+
return Some(Diagnostic::new(
106+
AsyncioDanglingTask {
107+
expr: name.id.to_string(),
108+
method: Method::CreateTask,
109+
},
110+
expr.range(),
111+
));
112+
}
112113
}
113114
}
114115
}

0 commit comments

Comments
 (0)