Skip to content

Fix standalone comment before binary op causing unnecessary split#5113

Open
HoraDomu wants to merge 1 commit intopsf:mainfrom
HoraDomu:fix/comment-before-binary-op-3713
Open

Fix standalone comment before binary op causing unnecessary split#5113
HoraDomu wants to merge 1 commit intopsf:mainfrom
HoraDomu:fix/comment-before-binary-op-3713

Conversation

@HoraDomu
Copy link
Copy Markdown

Fixes #3713

… A standalone comment before an arithmetic/comparator expression was inside brackets and caused delimiter_split to use the operator as a split point. It was breaking the expression across lines. The fix was when the first leaf is a standalone comment and the delimter priority is below LOGIC_PRIORITY, raise CannotSplit to defer to standalone_comment_split. This peels off the comment first, and then lets the expression stay on one line if it fits.
@HoraDomu
Copy link
Copy Markdown
Author

This fixes #3713

@github-actions
Copy link
Copy Markdown
Contributor

diff-shades results comparing this PR (ca2f3dd) to main (8dcc486):

--preview style (View full diff):
╭─────────────────────── Summary ────────────────────────╮
│ 5 projects & 11 files changed / 61 changes [+14/-47]   │
│                                                        │
│ ... out of 2 919 219 lines, 13 720 files & 22 projects │
╰────────────────────────────────────────────────────────╯

Differences found.

--stable style (View full diff):
╭─────────────────────── Summary ────────────────────────╮
│ 5 projects & 11 files changed / 61 changes [+14/-47]   │
│                                                        │
│ ... out of 2 919 219 lines, 13 720 files & 22 projects │
╰────────────────────────────────────────────────────────╯

Differences found.


What is this? | Workflow run | diff-shades documentation

@cobaltt7
Copy link
Copy Markdown
Collaborator

Thanks! This looks great, but a few notes here:

  • This changes Black's formatting, so it needs to be gated to the Preview style. See 01c29bd for a good recent example of how to do this.
  • Please add a changelog entry.
  • Could you add a test with a long operation that stays wrapped?
  • Nit: In tests, if you want to ensure code doesn't change at all, you can omit the "output" section entirely (including the comment). This helps keeps tests concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A comment before a multiplication line inside a func call makes the line unnecessarily explode

2 participants