Prevent squeezing of hanging comments inside expressions #83
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.
Closes #77 and fixes the CI.
This takes us one step further out from
list_comments
. The idea here is that the initial parser considers comments and whitespace-only lines a "prefix" to an actual token (significant newlines get their own token).generate_comments()
turns each comment into its ownLeaf
node. The previous code worked because expression-terminating newlines are a token in their own right in Python, so comments that hung on the end of expressions had no newline before the next token.With this proposal, instead of trying to figure out when it's safe to preserve the whitespace in front of a comment, we just note how much whitespace there was (adjusting for Black's auto-added two spaces). Then, we add that to the prefix (after any newlines), black has the option of respecting it or blowing it away, if it's going to break up the line.
As in the previous approach, this makes no attempt to compare the alignment across lines and only preserve extra whitespace when it actually does do alignment.