From 9e32585cb1e83dbaf6cd010ed4462d72e528067d Mon Sep 17 00:00:00 2001 From: Chris Pryer <14341145+cnpryer@users.noreply.github.com> Date: Thu, 20 Jul 2023 02:52:32 -0400 Subject: [PATCH] Use `dangling_node_comments` in `lambda` formatting (#5903) --- .../src/expression/expr_lambda.rs | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/ruff_python_formatter/src/expression/expr_lambda.rs b/crates/ruff_python_formatter/src/expression/expr_lambda.rs index 1b2dc485cd..c1f6100c59 100644 --- a/crates/ruff_python_formatter/src/expression/expr_lambda.rs +++ b/crates/ruff_python_formatter/src/expression/expr_lambda.rs @@ -1,4 +1,4 @@ -use crate::comments::dangling_comments; +use crate::comments::dangling_node_comments; use crate::context::PyFormatContext; use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses}; use crate::other::arguments::ArgumentsParentheses; @@ -6,7 +6,7 @@ use crate::AsFormat; use crate::{FormatNodeRule, PyFormatter}; use ruff_formatter::prelude::{space, text}; use ruff_formatter::{write, Buffer, FormatResult}; -use ruff_python_ast::node::{AnyNodeRef, AstNode}; +use ruff_python_ast::node::AnyNodeRef; use rustpython_parser::ast::ExprLambda; #[derive(Default)] @@ -20,15 +20,6 @@ impl FormatNodeRule for FormatExprLambda { body, } = item; - // It's possible for some `Arguments` of `lambda`s to be assigned dangling comments. - // - // a = ( - // lambda # Dangling - // : 1 - // ) - let comments = f.context().comments().clone(); - let dangling = comments.dangling_comments(args.as_any_node_ref()); - write!(f, [text("lambda")])?; if !args.args.is_empty() { @@ -48,7 +39,13 @@ impl FormatNodeRule for FormatExprLambda { text(":"), space(), body.format(), - dangling_comments(dangling) + // It's possible for some `Arguments` of `lambda`s to be assigned dangling comments. + // + // a = ( + // lambda # Dangling + // : 1 + // ) + dangling_node_comments(args.as_ref()) ] ) }