Skip to content

Commit

Permalink
Allow capitalized names for logger candidate heuristic match (#6356)
Browse files Browse the repository at this point in the history
Closes #6353.
  • Loading branch information
charliermarsh authored Aug 4, 2023
1 parent 78a3703 commit d788957
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
name = "world"
logging.info(f"Hello {name}")
logging.log(logging.INFO, f"Hello {name}")

_LOGGER = logging.getLogger()
_LOGGER.info(f"{__name__}")
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ G004.py:5:27: G004 Logging statement uses f-string
4 | logging.info(f"Hello {name}")
5 | logging.log(logging.INFO, f"Hello {name}")
| ^^^^^^^^^^^^^^^ G004
6 |
7 | _LOGGER = logging.getLogger()
|

G004.py:8:14: G004 Logging statement uses f-string
|
7 | _LOGGER = logging.getLogger()
8 | _LOGGER.info(f"{__name__}")
| ^^^^^^^^^^^^^ G004
|


8 changes: 7 additions & 1 deletion crates/ruff_python_semantic/src/analyze/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ pub fn is_logger_candidate(
// logger names.
if let Some(call_path) = collect_call_path(value) {
if let Some(tail) = call_path.last() {
if tail.starts_with("log") || tail.ends_with("logger") || tail.ends_with("logging") {
if tail.starts_with("log")
|| tail.ends_with("logger")
|| tail.ends_with("logging")
|| tail.starts_with("LOG")
|| tail.ends_with("LOGGER")
|| tail.ends_with("LOGGING")
{
return true;
}
}
Expand Down

0 comments on commit d788957

Please sign in to comment.