-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix incorect placement of trailing stub function comments #11632
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
MichaReiser
added
bug
Something isn't working
formatter
Related to the formatter
labels
May 31, 2024
MichaReiser
commented
May 31, 2024
@@ -240,7 +240,8 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite { | |||
preceding_stub.end(), | |||
f.context().source(), | |||
) < 2 | |||
}); | |||
}) | |||
&& !preceding_comments.has_trailing_own_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.
This is the actual fix
MichaReiser
changed the title
fix function trailing comments
Fix misplacement of trailing stub function comments
May 31, 2024
MichaReiser
changed the title
Fix misplacement of trailing stub function comments
Fix incorecty placement of trailing stub function comments
May 31, 2024
MichaReiser
changed the title
Fix incorecty placement of trailing stub function comments
Fix incorect placement of trailing stub function comments
May 31, 2024
dhruvmanila
approved these changes
May 31, 2024
..._python_formatter/resources/test/fixtures/ruff/statement/stub_functions_trailing_comments.py
Show resolved
Hide resolved
MichaReiser
force-pushed
the
fix-function-trailing-comments
branch
from
May 31, 2024 12:02
8dab64a
to
53b7f53
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This fixes an issue in the formatter where it reorder comments or, worse, moved trailing stub function comments into the next's function body.
The problem is that the formatter uses
line_suffix
for the trailing comments and the line suffixes are only flushed after the next newline. However, there's no such newline directly after the comment(s) because the formatter now allows newlines to be omitted between stub functions.The fix of this PR is to match Black's behavior to insert the empty lines if a collapsed stub has a trailing comment. I'm not very fond of the empty lines, because I think the comments should remain close to the stub body and not be separated by empty lines but it is consistent with how we format trailing function comments in other places and matches Black.
Closes #11569
Test Plan
See added tests