-
Notifications
You must be signed in to change notification settings - Fork 2k
Warn when using % operator on an f-string #24159
Copy link
Copy link
Closed
Labels
acceptedReady for implementationReady for implementationruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
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
- Mismatching number of %-placeholders in string formatting #24031 — original report
F507: Fix false negative for non-tuple RHS in%-formatting #24142 — F507 fix for non-tuple RHS
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedReady for implementationReady for implementationruleImplementing or modifying a lint ruleImplementing or modifying a lint rule