Add a with_dangling_comments to the parenthesized formatter (#6402)

See: https://github.com/astral-sh/ruff/pull/6376#discussion_r1285514328.
This commit is contained in:
Charlie Marsh 2023-08-07 15:12:12 -04:00 committed by GitHub
parent bb96647d66
commit 8919b6ad9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 82 deletions

View file

@ -1,9 +1,7 @@
use ruff_python_ast::node::AnyNodeRef;
use ruff_python_ast::{ExprSet, Ranged};
use crate::expression::parentheses::{
parenthesized_with_dangling_comments, NeedsParentheses, OptionalParentheses,
};
use crate::expression::parentheses::{parenthesized, NeedsParentheses, OptionalParentheses};
use crate::prelude::*;
use crate::FormatNodeRule;
@ -25,7 +23,9 @@ impl FormatNodeRule<ExprSet> for FormatExprSet {
let comments = f.context().comments().clone();
let dangling = comments.dangling_comments(item);
parenthesized_with_dangling_comments("{", dangling, &joined, "}").fmt(f)
parenthesized("{", &joined, "}")
.with_dangling_comments(dangling)
.fmt(f)
}
fn fmt_dangling_comments(&self, _node: &ExprSet, _f: &mut PyFormatter) -> FormatResult<()> {