Skip to content

W1203 with F-strings #2354

@pzelnip

Description

@pzelnip

Question

The logging-fstring-interpolation (W1203) warning reads:

  | Use % formatting in logging functions and pass the % parameters as arguments 
Used when a logging statement has a call form of "logging.<logging method>
(format_string.format(format_args...))". Such calls should use % formatting instead, 
but leave interpolation to the logging function by passing the parameters as arguments.
This message is emitted if f-string was used, and it can be disabled if you like.

It's not clear to me from that paragraph if its recommended to still use the formatting operator in logging statements, or if f-strings should be used. My understanding is the original intent of W1203 was to prefer the formatting operator over calls to format() as then the string interpolation is done lazily. I'm guessing the same is true with f-strings correct? Ie F-strings would not be evaluated lazily, so the same reasons for preferring the formatting operator over .format() with log statements apply, and as such the same warning is emitted when f-strings are used with log statements.

Is that correct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions