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

Hug power operators if its operands are "simple" #2726

Merged
merged 12 commits into from Jan 25, 2022
2 changes: 1 addition & 1 deletion CHANGES.md
Expand Up @@ -17,7 +17,7 @@
- Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700)
- Unparenthesized tuples on annotated assignments (e.g
`values: Tuple[int, ...] = 1, 2, 3`) now implies 3.8+ (#2708)
- Power operators now "hug" their operands if they're both "simple" (#2726)
- Remove spaces around power operators if both operands are simple (#2726)

### Packaging

Expand Down
4 changes: 2 additions & 2 deletions docs/the_black_code_style/current_style.md
Expand Up @@ -292,8 +292,8 @@ multiple lines. This is so that _Black_ is compliant with the recent changes in
style guide, which emphasizes that this approach improves readability.

Almost all operators will be surrounded by single spaces, the only exceptions are unary
operators (`+`, `-`, and `~`), and power operators when both its operands are considered
"simple". For power ops, an operand is considered "simple" if it's only a NAME, numeric
operators (`+`, `-`, and `~`), and power operators when both operands are simple.
For power ops, an operand is considered simple if it's only a NAME, numeric
CONSTANT, or attribute access (chained attribute access is allowed), with or without a
preceding unary operator.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reading it through once more, we could also say that the surrounding spaces are removed for unaries and simple powers. Now it just says that they are an exception to the rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm a little confused, could you elaborate?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh sorry, I missed this: I meant to say that we don't actually say what happens to unaries and powers. We only say that they are an exception to the rule. Maybe something like: "[the only exceptions are unaries and simple pows], for which the spaces are removed."


Expand Down