-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect f-string application #6889
Comments
Hi @hotpxl on what version did this used to work? Could you help us determine when this regression was introduced? |
realized my original description is misleading, corrected the wording |
It seems like the case of implicit string concatenation and as there are no placeholder in the first string, it's not being considered. If you change the code to |
Yeah, we probably need to add the f prefix to all segments in the implicit concat, is my guess. |
another example: print('{{ ' '{} {}'.format(1, 2)) $ ruff check --select UP032 test.py --diff
--- test.py
+++ test.py
@@ -1 +1 @@
-print('{{ ' '{} {}'.format(1, 2))
+print('{{ ' f'{1} {2}') the correct version is
|
Won't that potentially trigger another violation because some parts now use f-strings unnecessarily? |
surprisingly, no print(f'{{ ')
but print(f'{{ ' f'{1} {2}')
but even if it did, F541 is autofixable too. just gotta autofix in the right order |
No, we don't flag pieces of an implicit concatenation, if at least one segment contains a placeholder. (This is intentional.) |
Looks like this was fixed back in November in #8697 🥳 |
Python file
Command
Vanilla Ruff, no settings, built from master
The ruff output is
which is incorrect. The old code, when calling
.format
, collapses the double braces in{{hello}}
. But the Ruff version doesn'tThe text was updated successfully, but these errors were encountered: