-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add formatter support for call and class definition Arguments
#6274
Conversation
@@ -252,7 +252,7 @@ impl<'ast> Format<PyFormatContext<'ast>> for EmptyWithDanglingComments<'_> { | |||
[group(&format_args![ | |||
self.opening, | |||
// end-of-line comments | |||
dangling_comments(&self.comments[..end_of_line_split]), | |||
trailing_comments(&self.comments[..end_of_line_split]), |
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.
We don't want these to break, IIUC.
class_definition: &'a StmtClassDef, | ||
} | ||
|
||
impl Format<PyFormatContext<'_>> for FormatInheritanceClause<'_> { |
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.
We get all of this for free now, I think.
#[derive(Default)] | ||
pub struct FormatArguments; | ||
|
||
impl FormatNodeRule<Arguments> for FormatArguments { |
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.
This is largely moved from expr_call
.
b5af1c1
to
4d34062
Compare
Looking into ecosystem failure. |
(Need to fix a few things.) |
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinux
Windows
|
4d34062
to
1315f7c
Compare
1315f7c
to
e277615
Compare
## Summary Based on the confusion here: #6274 (comment). I looked into moving this logic into `placement.rs`, but I think it's trickier than it may appear.
Micha suggested this in #6274 (comment), and it allows us to unify the implementations for arguments and type params.
Based on feedback here: #6274 (comment).
Summary
This PR leverages the
Arguments
AST node introduced in #6259 in the formatter, which ensures that we correctly handle trailing comments in calls, like:(Previously, this was treated as a leading comment on
pass
.)This also allows us to unify the argument handling across calls and class definitions.
Test Plan
A bunch of new fixture tests, plus improved Black compatibility.