mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-30 07:08:07 +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
|
@ -108,14 +108,14 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
|||
//
|
||||
// Unlike other expression parentheses, tuple parentheses are part of the range of the
|
||||
// tuple itself.
|
||||
elts if is_parenthesized(*range, elts, f.context().source())
|
||||
_ if is_parenthesized(*range, elts, f.context().source())
|
||||
&& self.parentheses != TupleParentheses::StripInsideForLoop =>
|
||||
{
|
||||
parenthesized("(", &ExprSequence::new(elts), ")").fmt(f)
|
||||
parenthesized("(", &ExprSequence::new(item), ")").fmt(f)
|
||||
}
|
||||
elts => match self.parentheses {
|
||||
TupleParentheses::Subscript => group(&ExprSequence::new(elts)).fmt(f),
|
||||
_ => parenthesize_if_expands(&ExprSequence::new(elts)).fmt(f),
|
||||
_ => match self.parentheses {
|
||||
TupleParentheses::Subscript => group(&ExprSequence::new(item)).fmt(f),
|
||||
_ => parenthesize_if_expands(&ExprSequence::new(item)).fmt(f),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -128,18 +128,20 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
|
|||
|
||||
#[derive(Debug)]
|
||||
struct ExprSequence<'a> {
|
||||
elts: &'a [Expr],
|
||||
tuple: &'a ExprTuple,
|
||||
}
|
||||
|
||||
impl<'a> ExprSequence<'a> {
|
||||
const fn new(elts: &'a [Expr]) -> Self {
|
||||
Self { elts }
|
||||
const fn new(expr: &'a ExprTuple) -> Self {
|
||||
Self { tuple: expr }
|
||||
}
|
||||
}
|
||||
|
||||
impl Format<PyFormatContext<'_>> for ExprSequence<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
|
||||
f.join_comma_separated().nodes(self.elts.iter()).finish()
|
||||
f.join_comma_separated(self.tuple.end())
|
||||
.nodes(&self.tuple.elts)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue