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
Summary
Currently, none of the F50x rules fire when the left-hand side of
%is an f-string, because the check only matchesExpr::StringLiteral. This means code like: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
F507: Fix false negative for non-tuple RHS in%-formatting #24142 — F507 fix for non-tuple RHS