-
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
Use parenthesized_with_dangling_comments
in arguments formatter
#6376
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,9 +5,8 @@ use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; | |
use ruff_text_size::{TextRange, TextSize}; | ||
|
||
use crate::builders::empty_parenthesized_with_dangling_comments; | ||
use crate::comments::trailing_comments; | ||
use crate::expression::expr_generator_exp::GeneratorExpParentheses; | ||
use crate::expression::parentheses::{parenthesized, Parentheses}; | ||
use crate::expression::parentheses::{parenthesized_with_dangling_comments, Parentheses}; | ||
use crate::prelude::*; | ||
use crate::FormatNodeRule; | ||
|
||
|
@@ -35,18 +34,6 @@ impl FormatNodeRule<Arguments> for FormatArguments { | |
); | ||
} | ||
|
||
// If the arguments are non-empty, then a dangling comment indicates a comment on the | ||
// same line as the opening parenthesis, e.g.: | ||
// ```python | ||
// f( # This call has a dangling comment. | ||
// a, | ||
// b, | ||
// c, | ||
// ) | ||
let comments = f.context().comments().clone(); | ||
let dangling_comments = comments.dangling_comments(item.as_any_node_ref()); | ||
write!(f, [trailing_comments(dangling_comments)])?; | ||
|
||
let all_arguments = format_with(|f: &mut PyFormatter| { | ||
let source = f.context().source(); | ||
let mut joiner = f.join_comma_separated(item.end()); | ||
|
@@ -84,6 +71,17 @@ impl FormatNodeRule<Arguments> for FormatArguments { | |
joiner.finish() | ||
}); | ||
|
||
// If the arguments are non-empty, then a dangling comment indicates a comment on the | ||
// same line as the opening parenthesis, e.g.: | ||
// ```python | ||
// f( # This call has a dangling comment. | ||
// a, | ||
// b, | ||
// c, | ||
// ) | ||
let comments = f.context().comments().clone(); | ||
let dangling_comments = comments.dangling_comments(item.as_any_node_ref()); | ||
|
||
write!( | ||
f, | ||
[ | ||
|
@@ -103,7 +101,12 @@ impl FormatNodeRule<Arguments> for FormatArguments { | |
// ) | ||
// ``` | ||
// TODO(konstin): Doesn't work see wrongly formatted test | ||
parenthesized("(", &group(&all_arguments), ")") | ||
parenthesized_with_dangling_comments( | ||
"(", | ||
dangling_comments, | ||
&group(&all_arguments), | ||
")" | ||
) | ||
Comment on lines
+104
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we change the builder to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm thinking about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will handle separately since it would be unrelated to this change. |
||
] | ||
) | ||
} | ||
|
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.
@konstin - Is this still applicable? I can't tell what it applies to.
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.
i don't think think so