Skip to content
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

Formatter removes line break between implicitly concatenated strings #7052

Closed
cnpryer opened this issue Sep 1, 2023 · 2 comments · Fixed by #7679
Closed

Formatter removes line break between implicitly concatenated strings #7052

cnpryer opened this issue Sep 1, 2023 · 2 comments · Fixed by #7679
Assignees
Labels
documentation Improvements or additions to documentation formatter Related to the formatter

Comments

@cnpryer
Copy link
Contributor

cnpryer commented Sep 1, 2023

Couldn't find an exact issue, but I'm almost certain this has been reported already.

Maybe related to #6936
Also see #5893

Line-length: 88

Black (23.7.0):

print(
    "aaaaaaa {:.2f}% "
    "aaaaaaaaaaaaaaaa".format(
        (
            ((df_aaaaaaaaaaa["fak"].isna()) | (df_aaaaaaaaaaa["fak"] == 0)).sum()
            / len(df_aaaaaaaaaaa)
        )
        * 100
    )
)

Ruff (0.0.287):

print(
    "aaaaaaa {:.2f}% " "aaaaaaaaaaaaaaaa".format(
        (
            ((df_aaaaaaaaaaa["fak"].isna()) | (df_aaaaaaaaaaa["fak"] == 0)).sum()
            / len(df_aaaaaaaaaaa)
        )
        * 100
    )
)

Playground: https://play.ruff.rs/126e4315-3c75-4268-b43a-12586c5da779

@cnpryer cnpryer changed the title Formatter removes line break between string and string with format method Formatter removes line break between implicitly concatenated strings with format method Sep 1, 2023
@cnpryer cnpryer changed the title Formatter removes line break between implicitly concatenated strings with format method Formatter removes line break between implicitly concatenated strings Sep 1, 2023
@charliermarsh charliermarsh added the formatter Related to the formatter label Sep 1, 2023
@MichaReiser MichaReiser self-assigned this Sep 2, 2023
@MichaReiser
Copy link
Member

Black applies special formatting for strings inside binary expressions. We have a "cheap" implementation that works for the most simple cases but it falls short in more complicated settings. I hope to have a fix for this by next week.

@charliermarsh
Copy link
Member

We're marking this as an intentional deviation, since the resulting code doesn't exceed line width and reduces vertical spacing. (If you make the strings longer, we do split and format identically to Black.)

Can be closed once documented.

@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Sep 27, 2023
@charliermarsh charliermarsh self-assigned this Sep 27, 2023
charliermarsh added a commit that referenced this issue Sep 29, 2023
## Summary

Based on today's triage with @MichaReiser.

Closes #7652.
Closes #7320.
Closes #7052.
Closes #7314.
Closes #7317.
Closes #7323.
Closes #7320.
Closes #7315.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants