Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging-f-string falsely passes for Logger instances #6353

Closed
jmelahman opened this issue Aug 4, 2023 · 1 comment · Fixed by #6356
Closed

logging-f-string falsely passes for Logger instances #6353

jmelahman opened this issue Aug 4, 2023 · 1 comment · Fixed by #6356

Comments

@jmelahman
Copy link

logging-f-string

  • A minimal code snippet that reproduces the bug.
import logging

logging.info(f"{__name__}")

_LOGGER = logging.getLogger()
_LOGGER.info(f"{__name__}")

  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.
$ ruff check --isolated --select G004 repro.py
repro.py:3:14: G004 Logging statement uses f-string
Found 1 error.

while pylint's and flake8 will both error for the latter,

$ flake8 repro.py 
repro.py:3:14: G004 Logging statement uses f-string
repro.py:6:14: G004 Logging statement uses f-string

$ pylint repro.py 
************* Module repro
repro.py:3:0: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
repro.py:6:0: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)

-----------------------------------
Your code has been rated at 2.50/10
 

  • The current Ruff settings (any relevant sections from your pyproject.toml).

  • The current Ruff version (ruff --version).
$ ruff --version
ruff 0.0.282
@charliermarsh
Copy link
Member

Unfortunately we don't have the ability to know definitely whether a given variable is a logger object from the standard library. Neither does Flake8 or Pylint, so it's all a matter of heuristics that trade off false negatives vs. false positives. It looks like _LOGGER doesn't match our heuristic. (Anything ending with logger does, but it's not case insensitive.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants