Expand parents whenever open-parenthesis comments are present#6389
Merged
charliermarsh merged 1 commit intomainfrom Aug 8, 2023
Merged
Expand parents whenever open-parenthesis comments are present#6389charliermarsh merged 1 commit intomainfrom
charliermarsh merged 1 commit intomainfrom
Conversation
35d3d78 to
b16fc25
Compare
Member
Author
|
We still get this wrong: a = ( # type: ignore
int( # type: ignore
int( # type: ignore
int( # type: ignore
6
)
)
)
)Formatting as: a = int( # type: ignore # type: ignore
int( # type: ignore
int( # type: ignore
6
)
)
)But I think that's a separate issue. |
Contributor
PR Check ResultsBenchmarkLinuxWindows |
b16fc25 to
e3ca4e6
Compare
e3ca4e6 to
3eaf235
Compare
Member
Author
|
What's the current sentiment on this change? I think I'm currently in favor, though it is a meaningful deviation (on unformatted code; on Black-formatted code, the behavior should be the same). |
MichaReiser
approved these changes
Aug 8, 2023
Member
MichaReiser
left a comment
There was a problem hiding this comment.
I'm in favor because it is consistent with the trailing_comments formatting and helps keep pragma comments close to where they were placed in the source.
We can reconsider whether we should expand the parent of trailing comments in general, but this would need to be its own discusison.
konstin
approved these changes
Aug 8, 2023
durumu
pushed a commit
to durumu/ruff
that referenced
this pull request
Aug 12, 2023
…-sh#6389) ## Summary This PR modifies our dangling-open-parenthesis handling to _always_ expand the parent expression. So, for example, given: ```python a = int( # type: ignore int( # type: ignore int( # type: ignore 6 ) ) ) ``` We now retain that as stable formatting, instead of truncating like: ```python a = int(int(int(6))) # comment # comment # comment ``` Note that Black _does_ collapse comments like this _unless_ they're `# type: ignore` comments, and perhaps in some other cases, so this is an intentional deviation ([playground](https://black.vercel.app/?version=main&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4AFEAHpdAD2IimZxl1N_WlOfrjryFgvD4ScVsKPztqdHDGJUg5knO0JCdpUfW1IrWSNmIJPx95s0hP-pRNkCQNH64-eIznIvXjeWBQ5-qax0oNw4yMOuhwr2azvMRZaEB5r8IXVPHmRCJp7fe7y4290u1zzxqK_nAi6q_5sI-jsAAAAA8HgZ9V7hG3QAAZYBxQIAAGnCHXexxGf7AgAAAAAEWVo=)).
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.
Summary
This PR modifies our dangling-open-parenthesis handling to always expand the parent expression.
So, for example, given:
We now retain that as stable formatting, instead of truncating like:
Note that Black does collapse comments like this unless they're
# type: ignorecomments, and perhaps in some other cases, so this is an intentional deviation (playground).