-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
AST safety check fails to catch incorrect f-string change #4268
Comments
Confirmed this bug:
This is related to our lack of nested f-string support (#3746). I suppose our parser misparses this as two strings with an Other than adding actual support for this syntax, which is tracked in #3746, we should catch this in the AST safety check by being less lenient about the whitespace changes we allow in strings. |
Thank you for confirming this issue. I work around it like so: # fmt: off
print(f"{"|".join(['a','b','c'])}")
# fmt: on |
Fixes psf#4268 Previously we would allow whitespace changes in all strings, now only in docstrings.
Fixes #4268 Previously we would allow whitespace changes in all strings, now only in docstrings. Co-authored-by: Shantanu <[email protected]>
Fixes psf#4268 Previously we would allow whitespace changes in all strings, now only in docstrings. Co-authored-by: Shantanu <[email protected]>
Thank you for addressing this. Can the fix be expected in 24.2.1 or what's the next version that will include the fix? |
There will be a new release (24.3.0) soon. |
I just released 24.3.0 which includes this fix. |
I still have to wrap the code to not be formatted like this: # fmt: off
table += f"|{c}|{" | ".join(cols)}|\n"
# fmt: on Warning error: cannot format snapshot_manager/snapshot_manager/build_status.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /tmp/blk_aym4688c.log $ cat /tmp/blk_aym4688c.log
--- src
+++ dst
@@ -6797,11 +6797,11 @@
value=
Constant(
kind=
None, # NoneType
value=
- '|', # str
+ ' | ', # str
) # /Constant
) # /Attribute
keywords=
) # /Call
) # /FormattedValue |
Describe the style change
I wonder if f-strings should be formatted at all.
Examples in the current Black style
Desired style
Note
There's no change to the input here.
Additional context
Black formats the
"|"
to become" | "
and that affects the output which cannot be desired.Black formats the snippet like this currently:
The text was updated successfully, but these errors were encountered: