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

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

Closed
Akuli opened this issue Mar 3, 2021 · 2 comments
Closed

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

Akuli opened this issue Mar 3, 2021 · 2 comments
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. R: duplicate This issue or pull request already exists S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?

Comments

@Akuli
Copy link

Akuli commented Mar 3, 2021

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

@Akuli Akuli added the T: style What do we want Blackened code to look like? label Mar 3, 2021
@JelleZijlstra
Copy link
Collaborator

I agree, a PR would be welcome.

@ichard26 ichard26 added S: accepted The changes in this design / enhancement issue have been accepted and can be implemented F: parentheses Too many parentheses, not enough parentheses, and so on. labels May 30, 2021
@felix-hilden
Copy link
Collaborator

I believe this is the same proposal as #620, which has more discussion. So I'll close this issue in favor of it!

@felix-hilden felix-hilden added the R: duplicate This issue or pull request already exists label Jun 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: parentheses Too many parentheses, not enough parentheses, and so on. R: duplicate This issue or pull request already exists S: accepted The changes in this design / enhancement issue have been accepted and can be implemented T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

4 participants