mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
Handle right parens in join comma builder (#5711)
This commit is contained in:
parent
f0aa6bd4d3
commit
653429bef9
11 changed files with 159 additions and 136 deletions
|
@ -76,12 +76,13 @@ impl Format<PyFormatContext<'_>> for FormatInheritanceClause<'_> {
|
|||
bases,
|
||||
keywords,
|
||||
name,
|
||||
body,
|
||||
..
|
||||
} = self.class_definition;
|
||||
|
||||
let source = f.context().source();
|
||||
|
||||
let mut joiner = f.join_comma_separated();
|
||||
let mut joiner = f.join_comma_separated(body.first().unwrap().start());
|
||||
|
||||
if let Some((first, rest)) = bases.split_first() {
|
||||
// Manually handle parentheses for the first expression because the logic in `FormatExpr`
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::expression::parentheses::Parenthesize;
|
|||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{block_indent, format_with, space, text};
|
||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
|
||||
use rustpython_parser::ast::StmtDelete;
|
||||
use rustpython_parser::ast::{Ranged, StmtDelete};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtDelete;
|
||||
|
@ -35,7 +35,11 @@ impl FormatNodeRule<StmtDelete> for FormatStmtDelete {
|
|||
write!(f, [single.format().with_options(Parenthesize::IfBreaks)])
|
||||
}
|
||||
targets => {
|
||||
let item = format_with(|f| f.join_comma_separated().nodes(targets.iter()).finish());
|
||||
let item = format_with(|f| {
|
||||
f.join_comma_separated(item.end())
|
||||
.nodes(targets.iter())
|
||||
.finish()
|
||||
});
|
||||
parenthesize_if_expands(&item).fmt(f)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::builders::{parenthesize_if_expands, PyFormatterExtensions};
|
|||
use crate::{AsFormat, FormatNodeRule, PyFormatter};
|
||||
use ruff_formatter::prelude::{dynamic_text, format_with, space, text};
|
||||
use ruff_formatter::{write, Buffer, Format, FormatResult};
|
||||
use rustpython_parser::ast::StmtImportFrom;
|
||||
use rustpython_parser::ast::{Ranged, StmtImportFrom};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FormatStmtImportFrom;
|
||||
|
@ -39,7 +39,7 @@ impl FormatNodeRule<StmtImportFrom> for FormatStmtImportFrom {
|
|||
}
|
||||
}
|
||||
let names = format_with(|f| {
|
||||
f.join_comma_separated()
|
||||
f.join_comma_separated(item.end())
|
||||
.entries(names.iter().map(|name| (name, name.format())))
|
||||
.finish()
|
||||
});
|
||||
|
|
|
@ -68,8 +68,11 @@ impl Format<PyFormatContext<'_>> for AnyStatementWith<'_> {
|
|||
let comments = f.context().comments().clone();
|
||||
let dangling_comments = comments.dangling_comments(self);
|
||||
|
||||
let joined_items =
|
||||
format_with(|f| f.join_comma_separated().nodes(self.items().iter()).finish());
|
||||
let joined_items = format_with(|f| {
|
||||
f.join_comma_separated(self.body().first().unwrap().start())
|
||||
.nodes(self.items().iter())
|
||||
.finish()
|
||||
});
|
||||
|
||||
if self.is_async() {
|
||||
write!(f, [text("async"), space()])?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue