@@ -3,7 +3,6 @@ use std::fmt;
3
3
use ast:: Stmt ;
4
4
use ruff_diagnostics:: { Diagnostic , Violation } ;
5
5
use ruff_macros:: { derive_message_formats, violation} ;
6
- use ruff_python_ast:: call_path:: compose_call_path;
7
6
use ruff_python_ast:: { self as ast, Expr } ;
8
7
use ruff_python_semantic:: { analyze:: typing, Scope , SemanticModel } ;
9
8
use ruff_text_size:: Ranged ;
@@ -93,22 +92,24 @@ pub(crate) fn asyncio_dangling_task(expr: &Expr, semantic: &SemanticModel) -> Op
93
92
// Ex) `loop = ...; loop.create_task(...)`
94
93
if let Expr :: Attribute ( ast:: ExprAttribute { attr, value, .. } ) = func. as_ref ( ) {
95
94
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
+ }
112
113
}
113
114
}
114
115
}
0 commit comments