Skip to content

Mismatching number of %-placeholders in string #24164

@kaddkaka

Description

@kaddkaka

Summary

Like #24031.

Incorrect number of format specifies should give error.

There are already many good warnings and tips about using f-strings. Howerever I believe this code does not give any warning about number of arguments:

"" % banana

Since there is 0 placeholders in the string, there should be no reason to use % at all.

Cases to solve for(?) :

"hello" % x  # string literal
f"world" % y  # f-string? (maybe not because f-string interpolation could produce placeholders) 
"hello " * 3 % z  # can this be solved for free? 

Any more cases that are possible to solve? Easily?

Notes: x could be a tuple with 0 elements, but I can't see any meaningful value in code like that. But does that fact mean this should be it's own lint rule separate from F507?

Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    ruleImplementing 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