-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
exponentiation/power (**
) operator should always have spaces on either side like all (?) other operators
#3707
Comments
Hey, So originally Black treated power operators just like any other operator, padding it with a space on each side. However, enough people complained that we decided to change it (PR #2726). You can read this issue: #538, but the crux is that since power operators have such high precedence, they should hug their operands to avoid ambiguity. In fact, this is allowed by PEP 8, under "Other Recommendations" ...
The inconsistency in regards to the operands was simply a decision we made when we first changed. I honestly don't really remember why. Please read the original issue if you're curious. Anyway, given this is the first complaint IIRC post-change, it's unlikely we'll rollback on this. I hope that clears things up! |
**
) operator should always have spaces on either side like all (?) other operators**
) operator should always have spaces on either side like all (?) other operators
Thanks @ichard26 – I tried so many issue searches and that one still didn't come up. if the ship has sailed, it's sailed. Good to have this one for extra searchability at least. (For my part I'm finding the I am saddened that this proposal to add spaces when there are only two expressions (so |
Is there a way to configure it? Count me as a second complainer. I think the non-uniform treatment causes more confusion (for people trying to figure out the style) than the visual benefit. Separately, these sorts of backwards-incompatible changes can cause friction in codebases using black. We had to fight hard enough to get it to be used, and now we're having to go back and re-fight already resolved debates. Honestly, we'll probably freeze on the prior version until there's appetite+bandwidth to go to battle again. Personally, I think a feature like this should not have been added without a configurability flag. I'd love if there were a way to tell black to be accepting of both formats, and then maintainers of a codebase could use an extra flag to force it to update the style quietly without impacting others. |
@chebee7i for stability, note our stability policy in https://black.readthedocs.io/en/stable/the_black_code_style/index.html#stability-policy (in short, we'll only change the style once a year). |
Btw, is it expected that this should qualify as "simple"? Reading the docs...seems like it. -maxIntFloat = 2 ** sys.float_info.mant_dig
+maxIntFloat = 2**sys.float_info.mant_dig The original is certainly easier to read over the new. |
Describe the style change
put a single space around exponentiation (
**
) operator.Examples in the current Black style
Desired style
Additional context
This seems weirdly inconsistent with literally every other arithmetic operator I've tried in not putting spaces around the operators. Note that you do get spaces if there are parentheses around either operand, as shown in the example. This is also inconsistent. I've verified this against
main
.The text was updated successfully, but these errors were encountered: