Skip to content

logging-format-interpolation for f-stringsΒ #1788

@eddie-dunn

Description

@eddie-dunn

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

"""Docstring"""
import logging


def main():
    """Main"""
    url = 'http://example.com/%fe'
    # This works:
    logging.error(
        'url is %s | log method: %s', url, 'logging with parameters only')

    # This will crash the logger, but pylint will output
    # logging-format-interpolation:
    logging.error(
        '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')


main()

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions