Skip to content

parenthesized 'a if b else c' in dict #2018

@Akuli

Description

@Akuli

Examples in the current Black style This code looks terrible, but is unchanged by black:

if blah:
    if blah:
        if blah:
            blah = blah_blah_blah_blah_blah_blah_blah_blah_blah_blah_blah % {
                "blah_blah_blah": "a"
                if blah_blah_blah_blah_blah_blah_blah_blah_blah
                else "b"
            }

Desired style If I add parentheses before "a" and after "b", black converts it to this good-looking code:

if blah:
    if blah:
        if blah:
            blah = blah_blah_blah_blah_blah_blah_blah_blah_blah_blah_blah % {
                "blah_blah_blah": (
                    "a" if blah_blah_blah_blah_blah_blah_blah_blah_blah else "b"
                )
            }

It would be nice if black would always do this, regardless of whether the original code contains parentheses or not.

Additional context None

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: parenthesesToo many parentheses, not enough parentheses, and so on.R: duplicateThis issue or pull request already existsS: acceptedThe changes in this design / enhancement issue have been accepted and can be implementedT: 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