-
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
Keep user inserted optional parentheses #2237
Conversation
I think the consensus was that it's a good style, and in my mind it also extends to other places like you've pointed out. But what's up for contention is whether or not the functionality to keep existing formatting should be added. If I'm not mistaken, this would be akin to the magic trailing comma. I think it would be neat to have, but the maintainers may disagree. |
The reason I'm hesitant to merge this is that this introduces a weird dependency between runs in Black:
We had that same thing happen with the magic trailing commas and it introduced a long-running formatting instability (e.g. second run of the tool would reformat differently than the first run). Looking at the changes here, it looks a whole lot like this other case we fought for a long time. |
I understand the concern. The question would be is there a solution to make it work? There is the Obviously, I wouldn't have opened the initial issue and the PRs if I didn't believe it would be a useful addition to black and from the feedback so far, it seems that everybody agrees. |
I understand (and agree with) @ambv's concerns regarding similarity with the trailing comma situation. On the other hand, as someone who finds the final behaviour of trailing commas to be pretty great, I think this will similarly be a great improvement albeit with those pesky transition costs. There's some flavour of "how to reduce transition costs" in #2394.
So... does this mean that:
As someone interested in this as a user and a potential code contributor, the next steps here seem very unclear to me. What's the next thing to do here to help get this to a decision of what-to-do-here? |
@pradyunsg Personally, I would still like to see this move forward. However I feel that at the moment this would be a waist of my time, as it's not yet clear if something like this would ever be accepted. The current PR is enough to illustrate the point IMO. @felix-hilden wrote an excellent comment regarding that topic: #2156 (comment). Unfortunately, there haven't been any responses yet. |
Can you please make this available under an newline_bytes = self.settings.get("line_ending", settings.LineEnding).value.encode(
"ascii"
) |
I've marked the PR to as draft today. Unfortunately, I won't have time to work on it anytime soon. If anybody wants to pick this up and explore if it makes sense with an experimental flag, please feel free to do so! |
Honestly, if we start working on this feature I'd much rather it not be dependent on previous formatting. But this PR could be a good start for the implementation! It could also fit nicely under the |
Absolutely. If the current pain points get resolved, I imaging this might even be better than the current style. Still lots to discuss though. I would love it if black get's there some day. |
Unfortunately this has been stuck for over a year and has various merge conflicts. I'm also hesitant to increase our dependency on previous formatting. I'm going to close this for now, but we can consider in a new PR whether to make a similar change in the preview style. |
This is the followup to #2163 as it was seen as a noticeable improvement but rejected due to the large impact on existing codebases.
With this PR,
black
will now keep user-inserted optional parentheses if at least1
delimiter withLOGIC_PRIORITY
or higher is present. This would allow developers the option to actively choose the improved style while not changing existing codebases.If the idea itself is excepted, we could also discuss if this change should apply to all delimiters.
Example style
For more examples, please refer to the original PR #2163 or the issue #2156
Closes: #2156
/CC: @ambv, @JelleZijlstra, @cooperlees, @felix-hilden As you all have in some form participated in the original discussion, I'm especially interested in your thoughts.
Remaining tasks