Use dangling_node_comments in lambda formatting (#5903)

This commit is contained in:
Chris Pryer 2023-07-20 02:52:32 -04:00 committed by GitHub
parent fe7505b738
commit 9e32585cb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<ExprLambda> 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<ExprLambda> 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())
]
)
}