share common code

This commit is contained in:
Brent Westbrook 2025-12-11 15:13:47 -05:00
parent 5fee7534f7
commit d1b79f5400
No known key found for this signature in database
1 changed files with 6 additions and 16 deletions

View File

@ -409,25 +409,15 @@ impl Format<PyFormatContext<'_>> for FormatBody<'_> {
if is_expression_parenthesized((*body).into(), comments.ranges(), f.context().source())
&& comments.has_leading(*body)
{
trailing_comments(dangling).fmt(f)?;
if leading_body_comments.is_empty() {
write!(
f,
[
space(),
trailing_comments(dangling),
body.format().with_options(Parentheses::Always),
]
)
space().fmt(f)?;
} else {
write!(
f,
[
trailing_comments(dangling),
hard_line_break(),
body.format().with_options(Parentheses::Always)
]
)
hard_line_break().fmt(f)?;
}
body.format().with_options(Parentheses::Always).fmt(f)
} else {
write!(
f,