-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F-String formatting in assignment positions #13813
Comments
Hmm, I might have to fix this for the implicit concatenated string formatting because it handles this correctly and this now results in instable formatting |
One challenge is that we don't want to inline the comments if the expression breaks: a = f"test{
expression
}flat" f"can be {
joined
} togethereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" # inline Should be formatted to a = (
f"test{expression}flatcan be {
joined
} togethereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"
) # inline and not ```python
a = (
f"test{expression}flatcan be {
joined
} togethereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" # inline
) |
@MichaReiser Just want to check-in whether you ended up fixing this with implicit concatenated string formatting? |
I fixed the instability but I didn't fix the formatting. I suggest waiting with this task until the implicit concatenated string formatting PR is merged or that you work on top of it. We'll otherwise end up with horrible merge conflicts |
## Summary fixes: #13813 This PR fixes a bug in the formatting assignment statement when the value is an f-string. This is resolved by using custom best fit layouts if the f-string is (a) not already a flat f-string (thus, cannot be multiline) and (b) is not a multiline string (thus, cannot be flattened). So, it is used in cases like the following: ```py aaaaaaaaaaaaaaaaaa = f"testeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee{ expression}moreeeeeeeeeeeeeeeee" ``` Which is (a) `FStringLayout::Multiline` and (b) not a multiline. There are various other examples in the PR diff along with additional explanation and context as code comments. ## Test Plan Add multiple test cases for various scenarios.
The new f-string formatting in assignment-value positions seems inconsistent to me:
Gets formatted to:
Which avoids parentheses but it doesn't feel like the ideal formatting and it doesn't match the formatting if the expression starts out "flat"
The text was updated successfully, but these errors were encountered: