Skip to content

Warn when using % operator on an f-string #24159

@RenzoMXD

Description

@RenzoMXD

Summary

Currently, none of the F50x rules fire when the left-hand side of % is an f-string, because the check only matches Expr::StringLiteral. This means code like:

f"{banana}" % banana
f"hello %s %s" % (1, 2)

produces no warnings, even though mixing f-string interpolation with %-formatting is almost certainly a mistake — both serve the same purpose.

Proposal

Add a new rule (RUF072) that flags any use of % on an f-string. I can't think of a valid use case where using % over f-string interpolation is desired.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedReady for implementationruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions