-
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
Black unexpectedly alters comments and one-liner expressions when comments are placed above, when using --preview #3555
Labels
C: preview style
Issues with the preview and unstable style. Add the name of the responsible feature in the title.
T: bug
Something isn't working
Comments
JelleZijlstra
added
the
C: preview style
Issues with the preview and unstable style. Add the name of the responsible feature in the title.
label
Feb 7, 2023
Here's a related instance. Before:
After:
|
Got another report of moving comments that traces back to
|
hauntsaninja
added a commit
to hauntsaninja/black
that referenced
this issue
Dec 29, 2023
JelleZijlstra
pushed a commit
that referenced
this issue
Jan 2, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
C: preview style
Issues with the preview and unstable style. Add the name of the responsible feature in the title.
T: bug
Something isn't working
Describe the bug
When a comment is placed above a one-liner expression that uses a conditional statement, and
--preview
mode is on, black changes the comment and one-liner into a parenthesized block, or moves the comment to the end of the expression. The former situation with parentheses happens when the expression is preceded by at least one newline. The latter happens if there is no newline above the comment/expression. Neither of those formatting changes is expected.This one-liner expression syntax isn't the cleanest, and I would guess black has this behavior for cases where you assign the expression result to a variable, but perhaps this situation should still be left unaltered by black.
To Reproduce
Check this out in the black playground here
Input code:
Output using latest/
main
version of black with the--preview
argument:Expected behavior: No change to the original code whatsoever. That was Black's behavior prior to the latest version, 23.1.0.
Environment
The text was updated successfully, but these errors were encountered: