Skip to content

Commit

Permalink
Use join_comma_separated instead of ExprSequence
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed Jul 10, 2023
1 parent da5799d commit b7e02d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
18 changes: 17 additions & 1 deletion crates/ruff_python_formatter/src/expression/expr_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::expression::parentheses::{
default_expression_needs_parentheses, parenthesized, NeedsParentheses, Parentheses,
Parenthesize,
};
use crate::expression::sequence::ExprSequence;
use crate::prelude::*;
use ruff_formatter::{format_args, write, FormatRuleWithOptions};
use ruff_text_size::TextRange;
Expand Down Expand Up @@ -94,6 +93,23 @@ impl FormatNodeRule<ExprTuple> for FormatExprTuple {
}
}

#[derive(Debug)]
pub(crate) struct ExprSequence<'a> {
elts: &'a [Expr],
}

impl<'a> ExprSequence<'a> {
pub(crate) const fn new(elts: &'a [Expr]) -> Self {
Self { elts }
}
}

impl Format<PyFormatContext<'_>> for ExprSequence<'_> {
fn fmt(&self, f: &mut Formatter<PyFormatContext<'_>>) -> FormatResult<()> {
f.join_comma_separated().nodes(self.elts.iter()).finish()
}
}

impl NeedsParentheses for ExprTuple {
fn needs_parentheses(
&self,
Expand Down
1 change: 0 additions & 1 deletion crates/ruff_python_formatter/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub(crate) mod expr_unary_op;
pub(crate) mod expr_yield;
pub(crate) mod expr_yield_from;
pub(crate) mod parentheses;
pub(crate) mod sequence;
pub(crate) mod string;

#[derive(Default)]
Expand Down
21 changes: 0 additions & 21 deletions crates/ruff_python_formatter/src/expression/sequence.rs

This file was deleted.

10 changes: 6 additions & 4 deletions crates/ruff_python_formatter/src/statement/stmt_delete.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::builders::optional_parentheses;
use crate::builders::{optional_parentheses, PyFormatterExtensions};
use crate::comments::dangling_node_comments;
use crate::expression::parentheses::Parenthesize;
use crate::expression::sequence::ExprSequence;
use crate::{AsFormat, FormatNodeRule, PyFormatter};
use ruff_formatter::prelude::{block_indent, space, text};
use ruff_formatter::prelude::{block_indent, format_with, space, text};
use ruff_formatter::{write, Buffer, Format, FormatResult};
use rustpython_parser::ast::StmtDelete;

Expand Down Expand Up @@ -37,7 +36,10 @@ impl FormatNodeRule<StmtDelete> for FormatStmtDelete {
[single] => {
write!(f, [single.format().with_options(Parenthesize::IfBreaks)])
}
targets => optional_parentheses(&ExprSequence::new(targets)).fmt(f),
targets => {
let item = format_with(|f| f.join_comma_separated().nodes(targets.iter()).finish());
optional_parentheses(&item).fmt(f)
}
}
}

Expand Down

0 comments on commit b7e02d9

Please sign in to comment.