Commit 99d4014
committed
[
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.
Detect these cases and downgrade the fix applicability to `Unsafe`, so
users opt in via `--unsafe-fixes` instead of having the autofix silently
change runtime behavior. Side-effect detection keeps its existing
behavior; the new check just widens the set of unsafe cases.
Closes #15557pyflakes] Mark F523 fix as unsafe when it removes a meaningful .format(...) call1 parent 767df43 commit 99d4014
3 files changed
Lines changed: 72 additions & 2 deletions
File tree
- crates/ruff_linter
- resources/test/fixtures/pyflakes
- src/rules/pyflakes
- rules
- snapshots
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
920 | 920 | | |
921 | 921 | | |
922 | 922 | | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
923 | 931 | | |
924 | 932 | | |
925 | 933 | | |
| |||
929 | 937 | | |
930 | 938 | | |
931 | 939 | | |
932 | | - | |
933 | | - | |
| 940 | + | |
934 | 941 | | |
935 | 942 | | |
936 | 943 | | |
| |||
940 | 947 | | |
941 | 948 | | |
942 | 949 | | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
943 | 967 | | |
944 | 968 | | |
945 | 969 | | |
| |||
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| 335 | + | |
| 336 | + | |
335 | 337 | | |
336 | 338 | | |
337 | 339 | | |
338 | 340 | | |
339 | 341 | | |
340 | 342 | | |
341 | 343 | | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
0 commit comments