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 undocumented deviation: Redundant parentheses in boolean expression can lead to extra line breaks #8183

Closed
henribru opened this issue Oct 24, 2023 · 3 comments · Fixed by #8238
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@henribru
Copy link

Black:

def foo():
    while (
        not (aaaaaaaaaaaaaaaaaaaaa(bbbbbbbb, ccccccc)) and dddddddddd < eeeeeeeeeeeeeee
    ):
        pass

Ruff:

def foo():
    while not (
        aaaaaaaaaaaaaaaaaaaaa(bbbbbbbb, ccccccc)
    ) and dddddddddd < eeeeeeeeeeeeeee:
        pass
@MichaReiser MichaReiser added the formatter Related to the formatter label Oct 24, 2023
@MichaReiser MichaReiser added this to the Formatter: Stable milestone Oct 24, 2023
@MichaReiser
Copy link
Member

MichaReiser commented Oct 25, 2023

Could this be related/due to #8100?

@MichaReiser
Copy link
Member

I think the issue here is that we set first in CanOmitOptionalParenthesesVisitor to the UnaryExpr.value instead of the unary expression itself. I think we have the same problem for other nodes that start with a token (if expression, dict etc)

@MichaReiser
Copy link
Member

Okay I think I understand it now... It is an issue with can_omit_parentheses. Black uses different rules to test if the first or last node have parentheses.

  • first: Needs to start with parentheses. That excludes call expressions.
  • last: Needs to end with parentheses. Call, lists, etc

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
Development

Successfully merging a pull request may close this issue.

2 participants