-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixup comment handling on opening parenthesis in function definition #6381
Conversation
44a1b29
to
125504c
Compare
b63851f
to
efff187
Compare
write!(f, [parenthesized("(", &group(&format_inner), ")")]) | ||
write!( | ||
f, | ||
[parenthesized_with_dangling_comments( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now using the same utilities as all the other nodes (parenthesized_with_dangling_comments
, empty_parenthesized_with_dangling_comments
).
efff187
to
8237b5d
Compare
125504c
to
5fef49b
Compare
8237b5d
to
0de408d
Compare
PR Check ResultsBenchmarkLinux
Windows
|
5fef49b
to
7332d43
Compare
0de408d
to
78129e2
Compare
.skip_trivia() | ||
.skip_while(|t| { | ||
matches!( | ||
t.kind(), | ||
SimpleTokenKind::LParen | ||
| SimpleTokenKind::LBrace | ||
| SimpleTokenKind::LBracket | ||
) | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR but just popped to my head (may be relevant for other places where we apply the same logic). What happens if we have:
call(( a # test
))
I would expect this to be a comment of a
and not a dangling arguments comment.
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/function.py
Show resolved
Hide resolved
Please update your test plan with the similarity index. |
This fixes an instability with zulip, can you add x = () - a(#
b) to the tests? |
2873e6e
to
78129e2
Compare
b312f42
to
9b2557c
Compare
d55a7cf
to
26b1266
Compare
26b1266
to
3eed713
Compare
@konstin - That's a call though, this only touches function definitions, is it related? |
sorry, i got confused |
…stral-sh#6381) ## 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`.
Summary
I noticed some deviations in how we treat dangling comments that hug the opening parenthesis for function definitions.
For example, given:
We currently format as:
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 inparameters.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.99388django
: 0.99784warehouse
: 0.99504transformers
: 0.99404cpython
: 0.75913typeshed
: 0.74364After:
zulip
: 0.99386django
: 0.99784warehouse
: 0.99504transformers
: 0.99404cpython
: 0.75913typeshed
: 0.74409Meaningful improvement on
typeshed
, minor decrease onzulip
.