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. |
MichaReiser
left a comment
There was a problem hiding this comment.
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.
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.
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.
But I may be misunderstanding, it's a bit confusing.
There was a problem hiding this comment.
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.
What was the motivation for making this an associated function?
There was a problem hiding this comment.
(Not necessarily disagreeing, just looking to understand.)
There was a problem hiding this comment.
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.pymatches black's formatting.