astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
30.71k stars 1.02k forks source link

No error on `logging.Logger.warn` access [G010] #12295

Open rominf opened 1 month ago

rominf commented 1 month ago

Before creating this issue I searched for:

G010
logger warn
logger.warn

but could not find previous issue or PR.

Minimal code snippet (ruff_G010_no_call.py) that reproduces the bug:

"""No G010 on logging.Logger.warn access."""
import logging

logger = logging.getLogger()
warn = logger.warn
warn("Hello, world!")

I invoked ruff with:

$ ruff check ruff_G010_no_call.py --isolated --select G010 --target-version py313
$ ruff check ruff_G010_no_call.py --isolated --select ALL --target-version py313

but got no errors.

I expected to get G010 (https://docs.astral.sh/ruff/rules/logging-warn/) on line warn = logger.warn. The code like this is quite wide-spread, here are the results of GitHub search that show code most likely to be invalid in Python 3.13, but that won't be detected with the current version of ruff: https://github.com/search?q=%2F%28%3F-i%29%28logger%7Clogging%29.warn%24%2F+language%3APython&type=code

I installed ruff from PyPI first, then from https://github.com/astral-sh/ruff/archive/refs/heads/main.zip:

$ python3 --version 
Python 3.13.0b3
$ ruff --version
ruff 0.5.1

As a side note, current stable version of mypy does not find this issue either. mypy installed from master can find this issue though.

charliermarsh commented 1 month ago

This is known -- we use a heuristic to detect if a call is a "logging call", and we don't trace name symbols like that. I can't find an obvious issue to link this to though, so I'll leave it as-is.

charliermarsh commented 1 month ago

(logger.warn("...") should work, but I think you picked that up already :))