A literal str.format template and its arguments do not fit together

tx0/python:format-call-mismatchdefaultwarningbug

What it finds

"{} and {}".format(a), "{name}".format(nmae=x): str.format raises when its literal template and the arguments written next to it do not fit together: IndexError for a field without a value, KeyError for a missing name, and ValueError for a lone brace or a template that mixes {} with {0}.

Calls that unpack *args or **kwargs are only checked for what does not depend on them. Extra arguments are allowed, as str.format ignores them.

From the rule's source, format_call_mismatch.rs.

Example from the rule's tests
def messages(a, b, args, kwargs):    return [        "{} and {}".format(a),tx0 reports: the template has 2 {} fields, but 1 positional values are given        "{0} {2}".format(a, b),tx0 reports: the field {2} has no value; 2 positional values are given        "{name}".format(nmae=a),tx0 reports: the field {name} has no keyword argument of that name        "{} {0}".format(a, b),tx0 reports: the template mixes {} with numbered fields        "{".format(a),tx0 reports: str.format refuses this template: a { is never closed        "{} {}".format(*args),        "{x}".format(**kwargs),        "{{}} {}".format(a),        "{a.real:>{width}}".format(a=a, width=b),        "{}".format(a, b),    ]
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:format-call-mismatch" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:format-call-mismatch] reason="..."

tx0 explain tx0/python:format-call-mismatch shows the same in the terminal. Found a false positive? Report it.