Allow capitalized names for logger candidate heuristic match (#6356)

Closes https://github.com/astral-sh/ruff/issues/6353.
This commit is contained in:
Charlie Marsh 2023-08-04 19:25:34 -04:00 committed by GitHub
parent 78a370303b
commit d788957ec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -3,3 +3,6 @@ import logging
name = "world"
logging.info(f"Hello {name}")
logging.log(logging.INFO, f"Hello {name}")
_LOGGER = logging.getLogger()
_LOGGER.info(f"{__name__}")

View file

@ -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
|

View file

@ -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;
}
}