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

Commit
167 days ago
[`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>
Parents
Loading