Skip to content

printf-string-formatting

Pythonstyleno fixdefault: offpython/ruff

Reports a "..." % x whose format string and values pair up: a tuple with as many values as placeholders, a dict for named fields, or one value for one placeholder.

The % operator is the oldest of Python’s three ways to format a string. An f-string or .format puts the value where it is used, and a single value or a tuple that is mistaken for the arguments ("%s" % some_tuple) is a classic bug of %.

To fix, write an f-string, or use .format.

Reported
...
a = b = "x"
...
x = "%s" % y
...
...
python:
lint:
rules:
printf-string-formatting: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line printf-string-formatting in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP031 full