-
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
Insert newline after nested function or class statements #7946
Insert newline after nested function or class statements #7946
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
This comment was marked as outdated.
This comment was marked as outdated.
35c6120
to
9d6354c
Compare
9d6354c
to
f4978c6
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
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.
Leaving to @charliermarsh for the final review as his more familiar with the empty line rules than I
.filter(|last_child| !comments.has_trailing_own_line(*last_child)) | ||
}) | ||
.any(|last_child| { | ||
matches!( | ||
last_child, | ||
AnyNodeRef::StmtFunctionDef(_) | AnyNodeRef::StmtClassDef(_) | ||
) | ||
}) |
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.
Is any
here correct? Shouldn't we only test this for the last node:
if True:
if False:
def double(s):
...
#trailing comment, if gets excluded by the `filter` and the `any` will be true.
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 think successors
will short circuit as soon as it sees a node with a trailing comment, so the any
would be false.
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.
But I may be misunderstanding, it's a bit confusing.
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.
Tried to make the code clearer, it's a bit complex with the recursive logic unfortunately
A quality of life improvement mostly mechanical refactoring.
…r_class_statements
}; | ||
|
||
body.last().map(AnyNodeRef::from) | ||
} |
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.
What was the motivation for making this an associated function?
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.
(Not necessarily disagreeing, just looking to understand.)
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 needed to share it outside of placement where it used to be private helper function and then it seemed natural that "what is the last child of this node" is a property of node
Summary Insert a newline after nested function and class definitions, unless there is a trailing own line comment.
We need to e.g. format
as
even though
f()
is directly preceded by an if statement, not a function or class definition. See the comments and fixtures for trailing own line comment handling.Test Plan I checked that the new content of
newlines.py
matches black's formatting.