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

Use OptionalParentheses::Multiline for certain constants #7106

Closed
wants to merge 3 commits into from

Conversation

cnpryer
Copy link
Contributor

@cnpryer cnpryer commented Sep 3, 2023

Closes #7067

Summary

‼️ This solution is incomplete (see comment).

This PR updates the NeedsParentheses implementation for ExprConstant so that booleans, None, and ellipses use multiline to resolve the following difference with black:

# Input
def f():
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (
        True
    )

# Black (23.7.0)
def f():
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = (
        True
    )

# Ruff (0.0.287)
def f():
    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = True

Test Plan

Current and new fixtures.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 3, 2023

CodSpeed Performance Report

Merging #7106 will degrade performances by 3.61%

Comparing cnpryer:stmt-assign (ca90098) with main (834566f)

Summary

❌ 1 regressions
✅ 19 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main cnpryer:stmt-assign Change
formatter[numpy/globals.py] 1.3 ms 1.3 ms -3.61%

@cnpryer
Copy link
Contributor Author

cnpryer commented Sep 3, 2023

3.61%. Damn...

@cnpryer cnpryer marked this pull request as draft September 3, 2023 19:45
)

# This should not break over multiple lines
thing = True # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Copy link
Contributor Author

@cnpryer cnpryer Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a counter example to the current Multiline solution.

@cnpryer
Copy link
Contributor Author

cnpryer commented Sep 4, 2023

I'll reopen when I can look at this again.

@cnpryer cnpryer closed this Sep 4, 2023
@cnpryer cnpryer deleted the stmt-assign branch September 4, 2023 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatter collapses overlong assignment's parenthesized value
1 participant