Skip to content

Formatter: Comprehension ifs should break if the comprehension breaks #6063

@konstin

Description

@konstin

Black breaks the if into its own line if the comprehension breaks

a = (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    for f in bbbbbbbbbbbbbbb
    if f not in ccccccccccc
)

while we don't

a = (
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
    for f in bbbbbbbbbbbbbbb if f not in ccccccccccc
)

Conversely, parentheses should not require the target breaking

black:

aaaaaaaaaaaaaaaaaaaaa = (
    o for o in self.registry.values if o.__class__ is not ModelAdmin
)

ours:

aaaaaaaaaaaaaaaaaaaaa = (
    o
    for o in self.registry.values if o.__class__ is not ModelAdmin
)

Fixing this requires changing the grouping strategy for comprehensions and generator expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions