SIGN IN SIGN UP
astral-sh / ruff UNCLAIMED

An extremely fast Python linter and code formatter, written in Rust.

0 0 36 Rust

[`pyflakes`] Avoid removing the `format` call when it would change behavior (`F523`) (#25320)

## Summary

When every positional argument is unused, `F523` removes the entire
`.format(...)` call. That changes behavior whenever the format string
relies on the call:

* Brace escapes: `"{{".format("!")` returns `"{"`, but `"{{"` is two
characters.
* Named placeholders: `"{x}".format("!")` raises `KeyError`, but `"{x}"`
quietly succeeds.

This detects these cases and avoids removing the entire `format` call.
We also tried the "ideal" fix described on the issue of processing the
string to handle escapes ourselves, but just preserving the call seemed
like the better tradeoff in terms of complexity.

## Test plan

New mdtests based on the examples from the issue

Closes #15557

---------

Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
A
Aditya Singh committed
49882fa3844b9f93a7985dfd277a3348975bc576
Parent: f46ee08
Committed by GitHub <noreply@github.com> on 5/29/2026, 7:10:21 PM