mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
Use name directly in RUF006 (#9979)
This commit is contained in:
parent
3e9d761b13
commit
f40e012b4e
1 changed files with 18 additions and 17 deletions
|
@ -3,7 +3,6 @@ use std::fmt;
|
||||||
use ast::Stmt;
|
use ast::Stmt;
|
||||||
use ruff_diagnostics::{Diagnostic, Violation};
|
use ruff_diagnostics::{Diagnostic, Violation};
|
||||||
use ruff_macros::{derive_message_formats, 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_ast::{self as ast, Expr};
|
||||||
use ruff_python_semantic::{analyze::typing, Scope, SemanticModel};
|
use ruff_python_semantic::{analyze::typing, Scope, SemanticModel};
|
||||||
use ruff_text_size::Ranged;
|
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(...)`
|
// Ex) `loop = ...; loop.create_task(...)`
|
||||||
if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func.as_ref() {
|
if let Expr::Attribute(ast::ExprAttribute { attr, value, .. }) = func.as_ref() {
|
||||||
if attr == "create_task" {
|
if attr == "create_task" {
|
||||||
if typing::resolve_assignment(value, semantic).is_some_and(|call_path| {
|
if let Expr::Name(name) = value.as_ref() {
|
||||||
matches!(
|
if typing::resolve_assignment(value, semantic).is_some_and(|call_path| {
|
||||||
call_path.as_slice(),
|
matches!(
|
||||||
[
|
call_path.as_slice(),
|
||||||
"asyncio",
|
[
|
||||||
"get_event_loop" | "get_running_loop" | "new_event_loop"
|
"asyncio",
|
||||||
]
|
"get_event_loop" | "get_running_loop" | "new_event_loop"
|
||||||
)
|
]
|
||||||
}) {
|
)
|
||||||
return Some(Diagnostic::new(
|
}) {
|
||||||
AsyncioDanglingTask {
|
return Some(Diagnostic::new(
|
||||||
expr: compose_call_path(value).unwrap_or_else(|| "asyncio".to_string()),
|
AsyncioDanglingTask {
|
||||||
method: Method::CreateTask,
|
expr: name.id.to_string(),
|
||||||
},
|
method: Method::CreateTask,
|
||||||
expr.range(),
|
},
|
||||||
));
|
expr.range(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue