Summary
The percent-format-extra-named-arguments (F504) fix can change behavior if the extra args have side effects. It should probably be an always unsafe fix, or only safe if the args being removed are only literals.
playground
PS ~\Desktop\New_folder\ruff>Get-Content issue.py
"Hello, %(name)s" % {"greeting": print(1), "name": "World"}
PS ~\Desktop\New_folder\ruff>py issue.py
PS ~\Desktop\New_folder\ruff>uvx ruff check issue.py --isolated --select F
issue.py:1:1: F504 [*] `%`-format string has unused named argument(s): greeting
|
1 | "Hello, %(name)s" % {"greeting": print(1), "name": "World"}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ F504
|
= help: Remove extra named arguments: greeting
Found 1 error.
[*] 1 fixable with the `--fix` option.
PS ~\Desktop\New_folder\ruff>uvx ruff check issue.py --isolated --select F --fix
Found 1 error (1 fixed, 0 remaining).
PS ~\Desktop\New_folder\ruff>Get-Content issue.py
"Hello, %(name)s" % {"name": "World"}
PS ~\Desktop\New_folder\ruff>py issue.py
This also applies to string-dot-format-extra-named-arguments (F522) playground
This also applies to string-dot-format-extra-positional-arguments (F523) playground
Version
ruff 0.12.0 (87f0feb 2025-06-17) + playground
Summary
The percent-format-extra-named-arguments (F504) fix can change behavior if the extra args have side effects. It should probably be an always unsafe fix, or only safe if the args being removed are only literals.
playground
This also applies to string-dot-format-extra-named-arguments (F522) playground
This also applies to string-dot-format-extra-positional-arguments (F523) playground
Version
ruff 0.12.0 (87f0feb 2025-06-17) + playground