Fix incorect placement of trailing stub function comments (#11632)
This commit is contained in:
@@ -55,7 +55,7 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
||||
// newline between the comment and the node, but we _require_ two newlines. If there are
|
||||
// _no_ newlines between the comment and the node, we don't insert _any_ newlines; if there
|
||||
// are more than two, then `leading_comments` will preserve the correct number of newlines.
|
||||
empty_lines_after_leading_comments(f, comments.leading(item)).fmt(f)?;
|
||||
empty_lines_after_leading_comments(comments.leading(item)).fmt(f)?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
@@ -152,7 +152,7 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
|
||||
//
|
||||
// # comment
|
||||
// ```
|
||||
empty_lines_before_trailing_comments(f, comments.trailing(item), NodeKind::StmtClassDef)
|
||||
empty_lines_before_trailing_comments(comments.trailing(item), NodeKind::StmtClassDef)
|
||||
.fmt(f)?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -52,7 +52,7 @@ impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||
// newline between the comment and the node, but we _require_ two newlines. If there are
|
||||
// _no_ newlines between the comment and the node, we don't insert _any_ newlines; if there
|
||||
// are more than two, then `leading_comments` will preserve the correct number of newlines.
|
||||
empty_lines_after_leading_comments(f, comments.leading(item)).fmt(f)?;
|
||||
empty_lines_after_leading_comments(comments.leading(item)).fmt(f)?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
@@ -86,7 +86,7 @@ impl FormatNodeRule<StmtFunctionDef> for FormatStmtFunctionDef {
|
||||
//
|
||||
// # comment
|
||||
// ```
|
||||
empty_lines_before_trailing_comments(f, comments.trailing(item), NodeKind::StmtFunctionDef)
|
||||
empty_lines_before_trailing_comments(comments.trailing(item), NodeKind::StmtFunctionDef)
|
||||
.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,7 +240,8 @@ impl FormatRule<Suite, PyFormatContext<'_>> for FormatSuite {
|
||||
preceding_stub.end(),
|
||||
f.context().source(),
|
||||
) < 2
|
||||
});
|
||||
})
|
||||
&& !preceding_comments.has_trailing_own_line();
|
||||
|
||||
if !is_preceding_stub_function_without_empty_line {
|
||||
match self.kind {
|
||||
|
||||
Reference in New Issue
Block a user