Solvedpylint logging-format-interpolation for f-strings

Pylint will warn against using .format and % when logging. As the example below shows, I think it would be prudent to also output warnings when using f-strings.

Steps to reproduce

import logging

def main():
    url = ''
    # This works:
        'url is %s | log method: %s', url, 'logging with parameters only')

    # This will crash the logger, but pylint will output
    # logging-format-interpolation:
        'url is {} | log method: %s'.format(url), 'logging with .format')

    # This will also crash the logger, but pylint accepts it:
    logging.error(f'url is {url} | log method: %s', 'logging with f-string')


Current behavior

Pylint does not warn against f-string interpolation in loggers.

Expected behavior

Pylint should warn against f-string interpolation in loggers, just as it warns against .format-interpolation.

pylint --version output

pylint 1.8.1, 
astroid 1.6.0
Python 3.6.2 (default, Sep 22 2017, 12:45:49) 
[GCC 6.3.0 20170516]
23 Answers

✔️Accepted Answer

Please not! f-Strings are more readable and fast. We don't want to mix old-style and new-style formatting in our code (this is IMHO worse than not using'hello %s', name).

Other Answers:

Yeah, this warning seems like hardcore premature optimization.

Commenting on this issue won't change anything, if you don't agree with the warning, feel free to disable it, but this is going to be the default in pylint.

These kinds of decisions for defaults should be made by consensus rather than by fiat. Also, the imperious tone is not appreciated.

Sometimes I just don care. Practicality beats purity. 😉

I agree with @sscherfke. Code readability out weights the tiny efficiency increase.


You know what's even faster? Not logging at all and not writing any messages.

How about an option on pylint prudent behaviour for any stdout output?

More Issues: