Skip to content

Line breaking long sequence of assignments #3789

@awariac

Description

@awariac

Describe the style change

Hello,
We noticed that Black breaks long chains of assignments into multiple lines in a very unexpected way.

Example source code

AA = BB = CC = DD = EE = FF = GG = HH = JJ = KK = LL = MM = NN = OO = PP = QQ = RR = SS = TT = UU = WW = XX = YY = ZZ = 1

Examples in the current Black style

Black formats it in this way (last line is matched to max line length, but previous elements get 2 lines per one element):

AA = (
    BB
) = (
    CC
) = (
    DD
) = (
    EE
) = (
    FF
) = (
    GG
) = (
    HH
) = JJ = KK = LL = MM = NN = OO = PP = QQ = RR = SS = TT = UU = WW = XX = YY = ZZ = 1

Desired style

We would expect that all lines would break at max line length, and that the last line would be shorter.
We are not sure what would the desired splitting format, here are some propositions to be discussed:

#1
AA = BB = CC = DD = EE =  FF =  GG =  HH = JJ = KK = LL = MM = NN = OO = PP = QQ = (
RR ) = SS = TT = UU = WW = XX = YY = ZZ = 1
#2
AA = BB = CC = DD = EE =  FF =  GG =  HH = JJ = KK = LL = MM = NN = OO = PP =  ( QQ 
) = RR = SS = TT = UU = WW = XX = YY = ZZ = 1
#3 - looks the best for me
AA = BB = CC = DD = EE =  FF =  GG =  HH = JJ = KK = LL = MM = NN = OO = PP = QQ = ( 
    RR ) = SS = TT = UU = WW = XX = YY = ZZ = 1
#4
AA = BB = CC = DD = EE =  FF =  GG =  HH = JJ = KK = LL = MM = NN = OO = PP = QQ = (
    RR
) = SS = TT = UU = WW = XX = YY = ZZ = 1
#5
AA = BB = CC = DD = EE =  FF =  GG =  HH = JJ = KK = LL = MM = NN = OO = PP = QQ = \
    RR = SS = TT = UU = WW = XX = YY = ZZ = 1

All of above cases look more usable than currently formatted version.

Additional context

This a legitimate minified case from code, where we needed to assign a lot of alias names to an Enum field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: linetoolongBlack makes our lines too longT: styleWhat do we want Blackened code to look like?
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions