mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-01 08:07:31 +00:00
Use dangling_node_comments
in lambda
formatting (#5903)
This commit is contained in:
parent
fe7505b738
commit
9e32585cb1
1 changed files with 9 additions and 12 deletions
|
@ -1,4 +1,4 @@
|
||||||
use crate::comments::dangling_comments;
|
use crate::comments::dangling_node_comments;
|
||||||
use crate::context::PyFormatContext;
|
use crate::context::PyFormatContext;
|
||||||
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
use crate::expression::parentheses::{NeedsParentheses, OptionalParentheses};
|
||||||
use crate::other::arguments::ArgumentsParentheses;
|
use crate::other::arguments::ArgumentsParentheses;
|
||||||
|
@ -6,7 +6,7 @@ use crate::AsFormat;
|
||||||
use crate::{FormatNodeRule, PyFormatter};
|
use crate::{FormatNodeRule, PyFormatter};
|
||||||
use ruff_formatter::prelude::{space, text};
|
use ruff_formatter::prelude::{space, text};
|
||||||
use ruff_formatter::{write, Buffer, FormatResult};
|
use ruff_formatter::{write, Buffer, FormatResult};
|
||||||
use ruff_python_ast::node::{AnyNodeRef, AstNode};
|
use ruff_python_ast::node::AnyNodeRef;
|
||||||
use rustpython_parser::ast::ExprLambda;
|
use rustpython_parser::ast::ExprLambda;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -20,15 +20,6 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
body,
|
body,
|
||||||
} = item;
|
} = 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")])?;
|
write!(f, [text("lambda")])?;
|
||||||
|
|
||||||
if !args.args.is_empty() {
|
if !args.args.is_empty() {
|
||||||
|
@ -48,7 +39,13 @@ impl FormatNodeRule<ExprLambda> for FormatExprLambda {
|
||||||
text(":"),
|
text(":"),
|
||||||
space(),
|
space(),
|
||||||
body.format(),
|
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())
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue