From fc513684d20fe8ea12a0caf9be6cb625f71b4330 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Fri, 14 Nov 2025 17:42:47 -0500 Subject: [PATCH] update handle_unary_op_comment docs --- .../ruff_python_formatter/src/comments/placement.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_formatter/src/comments/placement.rs b/crates/ruff_python_formatter/src/comments/placement.rs index 234752ba53..39393b2e63 100644 --- a/crates/ruff_python_formatter/src/comments/placement.rs +++ b/crates/ruff_python_formatter/src/comments/placement.rs @@ -1831,7 +1831,7 @@ fn handle_lambda_comment<'a>( CommentPlacement::Default(comment) } -/// Move comment between a unary op and its operand before the unary op by marking them as trailing. +/// Move comment between a unary op and its operand before the unary op by marking them as leading. /// /// For example, given: /// ```python @@ -1841,8 +1841,13 @@ fn handle_lambda_comment<'a>( /// ) /// ``` /// -/// The `# comment` will be attached as a dangling comment on the enclosing node, to ensure that -/// it remains on the same line as the operator. +/// The `# comment` will be attached as a leading comment on the unary op, to ensure that +/// it doesn't fall between the operator and its operand: +/// ```python +/// ( # comment +/// not True +/// ) +/// ``` fn handle_unary_op_comment<'a>( comment: DecoratedComment<'a>, unary_op: &'a ast::ExprUnaryOp,