mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 21:28:21 +00:00
Consider logger candidate from logging
module only (#3878)
This commit is contained in:
parent
390d7dcf39
commit
b6155232ac
3 changed files with 15 additions and 7 deletions
|
@ -1,3 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
from distutils import log
|
||||||
|
|
||||||
logging.warn("Hello World!")
|
logging.warn("Hello World!")
|
||||||
|
log.warn("Hello world!") # This shouldn't be considered as a logger candidate
|
||||||
|
|
|
@ -8,19 +8,19 @@ expression: diagnostics
|
||||||
suggestion: "Convert to `warn`"
|
suggestion: "Convert to `warn`"
|
||||||
fixable: true
|
fixable: true
|
||||||
location:
|
location:
|
||||||
row: 3
|
row: 4
|
||||||
column: 8
|
column: 8
|
||||||
end_location:
|
end_location:
|
||||||
row: 3
|
row: 4
|
||||||
column: 12
|
column: 12
|
||||||
fix:
|
fix:
|
||||||
edits:
|
edits:
|
||||||
- content: warning
|
- content: warning
|
||||||
location:
|
location:
|
||||||
row: 3
|
row: 4
|
||||||
column: 8
|
column: 8
|
||||||
end_location:
|
end_location:
|
||||||
row: 3
|
row: 4
|
||||||
column: 12
|
column: 12
|
||||||
parent: ~
|
parent: ~
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,15 @@ use crate::context::Context;
|
||||||
/// ```
|
/// ```
|
||||||
pub fn is_logger_candidate(context: &Context, func: &Expr) -> bool {
|
pub fn is_logger_candidate(context: &Context, func: &Expr) -> bool {
|
||||||
if let ExprKind::Attribute { value, .. } = &func.node {
|
if let ExprKind::Attribute { value, .. } = &func.node {
|
||||||
let Some(call_path) = context
|
let Some(call_path) = (if let Some(call_path) = context.resolve_call_path(value) {
|
||||||
.resolve_call_path(value)
|
if call_path.first().map_or(false, |module| *module == "logging") {
|
||||||
.or_else(|| collect_call_path(value)) else {
|
Some(call_path)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
collect_call_path(value)
|
||||||
|
}) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
if let Some(tail) = call_path.last() {
|
if let Some(tail) = call_path.last() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue