mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:25:17 +00:00
![]() ## Summary Closes https://github.com/astral-sh/ruff/issues/6384, although I think the issue was fixed already on main, for the most part. The linked issue is around formatting expressions like: ```python def test(): ( yield #comment 1 * # comment 2 # comment 3 test # comment 4 ) ``` On main, prior to this PR, we now format like: ```python def test(): ( yield ( # comment 1 # comment 2 # comment 3 *test ) # comment 4 ) ``` Which strikes me as reasonable. (We can't test this, since it's a syntax error after for our parser, despite being a syntax error in both cases from CPython's perspective.) Meanwhile, Black does: ```python def test(): ( yield # comment 1 * # comment 2 # comment 3 test # comment 4 ) ``` So our formatting differs in that we move comments between the star and the expression above the star. As of this PR, we also support formatting this input, which is valid: ```python def test(): ( yield #comment 1 * # comment 2 # comment 3 test, # comment 4 1 ) ``` Like: ```python def test(): ( yield ( # comment 1 ( # comment 2 # comment 3 *test, # comment 4 1, ) ) ) ``` There were two fixes here: (1) marking starred comments as dangling and formatting them properly; and (2) supporting parenthesized comments for tuples that don't contain their own parentheses, as is often the case for yielded tuples (previously, we hit a debug assert). Note that this diff ## Test Plan cargo test |
||
---|---|---|
.. | ||
snapshots | ||
fixtures.rs |