You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I log to the root logger directly or if within a scope I call logging.getLogger and then log to that Logger, I will get the logging-fstring-interpolation warning, but if I have a function parameter that is hinted as a logging.Logger, I will not get the logging-fstring-interpolation warning on that logger:
"""A demonstration of a missing logging-fstring-interpolation warning."""importloggingMSG="we used an f-string in a logging statement"logging.error(f"Something bad happened: {MSG}")
file_logger=logging.getLogger(__name__)
file_logger.error(f"Something bad happened: {MSG}")
defmy_function(logger: logging.Logger) ->None:
"""A function that accepts a logger."""logging.error(f"Something bad happened: {MSG}")
function_logger=logging.getLogger(my_function.__name__)
function_logger.error(f"Something bad happened: {MSG}")
logger.error(f"Something bad happened: {MSG}") # no logging-fstring-interpolation warningclassMyClass: # pylint: disable=too-few-public-methods"""A class with a method that accepts a logger."""def__init__(self, logger: logging.Logger) ->None:
logging.error(f"Something bad happened: {MSG}")
class_logger=logging.getLogger(MyClass.__name__)
class_logger.error(f"Something bad happened: {MSG}")
logger.error(f"Something bad happened: {MSG}") # no logging-fstring-interpolation warning
Configuration
N/A
Command used
pylint a.py
Pylint output
$ pylint a.py
************* Module a
a.py:5:0: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
a.py:8:0: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
a.py:13:4: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
a.py:16:4: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
a.py:25:8: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
a.py:28:8: W1203: Use lazy % formatting in logging functions (logging-fstring-interpolation)
Expected behavior
I expect to get a logging-fstring-interpolation warning on the logger.error statements too.
Pylint version
astroid==2.15.4
pylint==2.17.4
### OS / Environment
Darwin
### Additional dependencies
_No response_
The text was updated successfully, but these errors were encountered:
I think it depends on #4813 and is not going to be solved as long as it's not done, so I'm hesitating to close as duplicate even if it seem it's two very different issues.
Yes, so it seems. Kind of a shocking to realize that astroid doesn't currently use type hints to infer the origin of an expression. It greatly diminishes the opportunities for this warning to be raised (and others as well I'm sure) in an object oriented setting.
Bug description
If I log to the root logger directly or if within a scope I call
logging.getLogger
and then log to thatLogger
, I will get thelogging-fstring-interpolation
warning, but if I have a function parameter that is hinted as alogging.Logger
, I will not get thelogging-fstring-interpolation
warning on that logger:Configuration
Command used
Pylint output
Expected behavior
I expect to get a
logging-fstring-interpolation
warning on thelogger.error
statements too.Pylint version
The text was updated successfully, but these errors were encountered: