An f-string is written inside a replacement field of another f-string

tx0/python:fstring-in-fstringstrictwarningmaintainability

What it finds

Since Python 3.12 an f-string may hold another f-string with the same quotes, and before that with different ones. Either way the reader has to match nested braces and quotes to see what is printed; a variable for the inner value reads more easily. Format specifications such as {x:>{width}} are not affected.

From the rule's source, fstring_in_fstring.rs.

Example from the rule's tests
def show(name, items, width):    print(f"{name}: {', '.join(f'<{i}>' for i in items)}")tx0 reports: this f-string is nested in a replacement field    print(f"{name:>{width}}")    print(f"{name!r}")
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:fstring-in-fstring" = "warning"

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:fstring-in-fstring] reason="..."

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