mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 05:26:23 +00:00
![]() ## Summary I noticed some deviations in how we treat dangling comments that hug the opening parenthesis for function definitions. For example, given: ```python def f( # first # second ): # third ... ``` We currently format as: ```python def f( # first # second ): # third ... ``` This PR adds the proper opening-parenthesis dangling comment handling for function parameters. Specifically, as with all other parenthesized nodes, we now detect that dangling comment in `placement.rs` and handle it in `parameters.rs`. We have to take some care in that file, since we have multiple "kinds" of dangling comments, but I added a bunch of test cases that we now format identically to Black. ## Test Plan `cargo test` Before: - `zulip`: 0.99388 - `django`: 0.99784 - `warehouse`: 0.99504 - `transformers`: 0.99404 - `cpython`: 0.75913 - `typeshed`: 0.74364 After: - `zulip`: 0.99386 - `django`: 0.99784 - `warehouse`: 0.99504 - `transformers`: 0.99404 - `cpython`: 0.75913 - `typeshed`: 0.74409 Meaningful improvement on `typeshed`, minor decrease on `zulip`. |
||
---|---|---|
.. | ||
black | ||
ruff | ||
import_black_tests.py |