-
Notifications
You must be signed in to change notification settings - Fork 921
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
New Rule: Formatted string passed to logging module PYL-W1203 #11854
Comments
I'm new to working with ruff but I would like to tackle this. |
This is already implemented as part of G001, G002 and G004. What is still needed though is an autofix, as we have hundreds of these violations and they are very tedious to fix manually. |
We're using the "G" rule and ruff does not detect this. |
I see it raised here: https://play.ruff.rs/4e92508d-36ee-476b-b67d-7bc6d8c1e457 |
It seems that the error fades, when I use for example |
Yes, that's currently a limitation of Ruff where it doesn't know the context from other modules. Currently, Ruff only looks at one file at a time but that's going to be changed in the future where we add support for multifile analysis. |
Actually it looks like those errors are either raised or not based only on the name of the object calling the So for example: msg = "test"
class Foo:
def __init__(self):
...
def error(self, msg: str):
raise ValueError(msg)
log = Foo()
log.error(f"{msg} failed") this raises the error but msg = "test"
class Foo:
def __init__(self):
...
def error(self, msg: str):
raise ValueError(msg)
foo = Foo()
foo.error(f"{msg} failed") this does not. This shows an error import logging
msg = "test"
logger = logging.getLogger("foo")
logger.error(f"{msg} failed") But this does not import logging
msg = "test"
foo = logging.getLogger("foo")
foo.error(f"{msg} failed") |
Deepsource warns you, when you use a formatted string with the logging module.
Example:
and suggest to use it with
%
like so:The text was updated successfully, but these errors were encountered: