Skip to content

Commit c50d6c3

Browse files
committed
handle non-node branches in comments in between statements
1 parent 9664474 commit c50d6c3

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/ruff_python_formatter/src/comments/placement.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,15 @@ fn handle_own_line_comment_between_statements<'a>(
569569
// y = 2
570570
// ```
571571
if max_empty_lines(&source[TextRange::new(comment.end(), following.start())]) == 0 {
572+
for token in SimpleTokenizer::new(source, TextRange::new(comment.end(), following.start()))
573+
{
574+
match token.kind() {
575+
SimpleTokenKind::Else | SimpleTokenKind::Finally => {
576+
return CommentPlacement::dangling(comment.enclosing_node(), comment);
577+
}
578+
_ => {}
579+
}
580+
}
572581
CommentPlacement::leading(following, comment)
573582
} else {
574583
CommentPlacement::trailing(preceding, comment)

0 commit comments

Comments
 (0)