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: overlong values without breakpoint are never parenthesized #6271

Closed
Tracked by #6203 ...
konstin opened this issue Aug 2, 2023 · 1 comment · Fixed by #6817
Closed
Tracked by #6203 ...

Formatter: overlong values without breakpoint are never parenthesized #6271

konstin opened this issue Aug 2, 2023 · 1 comment · Fixed by #6817
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@konstin
Copy link
Member

konstin commented Aug 2, 2023

Overlong values in e.g. assignment position without sometimes be parenthesized, this seems to depend on whether parenthesizing actually help too not be overlong anymore. The first step of fixing this issue is figuring out the exact criteria for what is indented and what isn't.

input and our output:

x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
x_aaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
y_aaaa = a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
z_aaaa = a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
x = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
x_aaaa = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
y_aaaa = "a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
z_aaaa = "a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

black:

x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
x_aaaa = (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
y_aaaa = (
    a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
z_aaaa = (
    a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
x = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
x_aaaa = (
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
y_aaaa = (
    "a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)
z_aaaa = "a.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
@konstin konstin added bug Something isn't working formatter Related to the formatter labels Aug 2, 2023
@konstin konstin changed the title Formatter: overlong attribute chains should be wrapped in parentheses Formatter: overlong value in assignment position without breakpoint are wrongly formatted Aug 2, 2023
@konstin konstin changed the title Formatter: overlong value in assignment position without breakpoint are wrongly formatted Formatter: overlong values in assignment position without breakpoint are wrongly formatted Aug 2, 2023
@konstin konstin added the help wanted Contributions especially welcome label Aug 2, 2023
@MichaReiser MichaReiser removed the help wanted Contributions especially welcome label Aug 3, 2023
@MichaReiser
Copy link
Member

This behavior isn't just specific to assignments but applies in general (I haven't understood the details yet).

I believe this is the relevant logic in black. Where it splits the line by adding optional parentheses, but only keeps them if all lines now fit.

I have a branch where I tried to get to the bottom of it but I haven't yet found out the right rules that apply (or messed up the Printer implementation)

This is the same as #6059.

@MichaReiser MichaReiser changed the title Formatter: overlong values in assignment position without breakpoint are wrongly formatted Formatter: overlong values without breakpoint are parenthesized Aug 3, 2023
@MichaReiser MichaReiser changed the title Formatter: overlong values without breakpoint are parenthesized Formatter: overlong values without breakpoint are never parenthesized Aug 3, 2023
@MichaReiser MichaReiser added this to the Formatter: Alpha milestone Aug 16, 2023
@MichaReiser MichaReiser self-assigned this Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
2 participants