-
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
Extend use of optional parentheses #2163
Conversation
Hi @cdce8p, I see you're a new contributor here, welcome! I took a quick look at your changes and I really like the new output. I probably won't be reviewing this (not qualified to do so yet) but I just wanted to provide my support for the formatting changes. Although unfortunately this does seem like the type of change that would be rejected for being too disruptive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this change too, but it's unfortunately a pretty big change.
and prevp_parent.type | ||
in { | ||
syms.subscript, | ||
syms.sliceop, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interacts a bit poorly with the magic trailing comma; we could have put this all in one line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to address those things once we have decided how to best continue with this PR.
I saw that too. As you might have noticed, the required code change itself isn't that big which is why I though a PR would be a good starting point for a discussion if it should be persuade any further. It also has the added benefit that anyone can try it for him-/herself. The question now becomes how to best continue with it. The way I see it there are a few options, some better suited then others:
Tbh I'm not sure what to do and in the end it's not my decision to make. Those are just some things I could think of and maybe there is also another way I haven't mentioned. If so, I'm eager to hear about it. |
As a side node, I just started to look at the result of the |
e56ed1c
to
3c92cc3
Compare
@JelleZijlstra What would be your opinion on how to continue with it? |
I vote to merge, but I'd like to hear what other maintainers think. |
I prefer this and think it makes us more consistent. So possibly worth the disruption to codebases. Wonder if it's worth a community vote going forward with invasive changes? |
* This change will effect almost all projects
👍🏻 I've gone ahead and added a changelog entry as well as fixed the remaining tests. Should be ready for review then |
No, I don't think you realize how disruptive of a formatting change this is so late in the game. When I originally made optional parentheses, I added the rule to only use them when there's more than one operator inside because even then this produced too many spurious parens, ballooning the number of lines in sometimes rather simple expressions. Python doesn't require parens around There cannot be a flag for it since all our flags disable behavior. They're not for choosing which out of two mutually exclusive approaches to follow. Hence we don't have a "singe quote" option, etc. Thanks for your contribution, I realize this would have made Black more internally consistent but I'm afraid this would really cause massive uproar for relatively little gain. I understand this is disappointing and nobody is disappointed in this as much as I am, but I believe we are too late in the project to make sweeping changes of this magnitude. |
@ambv I appreciate the feedback. Although I don't fully agree, I get your point. Since everyone so far agreed that the style itself is an improvement and consistent with the current one, would it at least be an option to keep user inserted parentheses in that case? That way we could use them when it makes sense without black overwriting the decision. |
For statements with just one priority delimiter it's often better / easier to read if optional parentheses are inserted. Some examples (from black itself):
Additional examples can be seen here: 74b47c1
This is already the default if at least two delimiters with the same max priority are present:
black/src/black/__init__.py
Lines 6760 to 6763 in b39999d
Notes
The only code change is the first commit: 4a4a3bc
Closes #2156
Remaining Todo's