Prevent squeezing of hanging comments inside expressions#83
Open
effigies wants to merge 1 commit into
Open
Conversation
Contributor
Author
|
@warsaw Just wanted to make sure you saw this, and I would be interested in your thoughts. Absolutely no rush, though. |
Contributor
Author
|
Gentle bump on this. I often have some more free time over the holidays, so would be able to iterate fairly quickly if there are changes that need to be made. |
This file contains hidden or 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
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.
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 ownLeafnode. 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.