Skip to content

Avoid extra parentheses in unary expressions#7428

Merged
charliermarsh merged 1 commit intomainfrom
charlie/unary
Sep 16, 2023
Merged

Avoid extra parentheses in unary expressions#7428
charliermarsh merged 1 commit intomainfrom
charlie/unary

Conversation

@charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Sep 16, 2023

Summary

This PR applies a similar fix to unary expressions as in #7424. Specifically, we only need to parenthesize the entire operator if the operand itself doesn't have parentheses, and requires parentheses.

Closes #7423.

Test Plan

cargo test

No change in similarity.

Before:

project similarity index total files changed files
cpython 0.76083 1789 1632
django 0.99982 2760 37
transformers 0.99957 2587 399
twine 1.00000 33 0
typeshed 0.99983 3496 18
warehouse 0.99923 648 18
zulip 0.99962 1437 22

After:

project similarity index total files changed files
cpython 0.76083 1789 1632
django 0.99982 2760 37
transformers 0.99957 2587 399
twine 1.00000 33 0
typeshed 0.99983 3496 18
warehouse 0.99923 648 18
zulip 0.99962 1437 22

@charliermarsh charliermarsh added the formatter Related to the formatter label Sep 16, 2023
@MichaReiser
Copy link
Member

Please double check that this isn't regressing the similarity index for our test-projects and update the PR summary with the metrics.

@charliermarsh charliermarsh merged commit 1880cce into main Sep 16, 2023
@charliermarsh charliermarsh deleted the charlie/unary branch September 16, 2023 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter incompatibility: extra parentheses around unary expression

2 participants