From dad0ab84ebb3316e99dc88897919a58ca8762f27 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 14 Feb 2024 19:51:35 +0530 Subject: [PATCH] Fix trailing comma visitor --- crates/ruff_python_formatter/src/other/f_string_element.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_formatter/src/other/f_string_element.rs b/crates/ruff_python_formatter/src/other/f_string_element.rs index 09c3a966e4e6f..0d477fe020ce4 100644 --- a/crates/ruff_python_formatter/src/other/f_string_element.rs +++ b/crates/ruff_python_formatter/src/other/f_string_element.rs @@ -182,7 +182,7 @@ impl Format> for FormatFStringExpressionElement<'_> { // expression can't contain a trailing comma. if self.context.should_remove_soft_line_breaks() && { let visitor = &mut CanContainTrailingCommaVisitor::default(); - AnyNodeRef::from(&**expression).visit_preorder(visitor); + visitor.visit_expr(expression); visitor.can_have_trailing_comma } { let options = f @@ -284,13 +284,13 @@ impl<'a> PreorderVisitor<'a> for CanContainTrailingCommaVisitor { AnyNodeRef::ExprList(ast::ExprList { elts, .. }) | AnyNodeRef::ExprTuple(ast::ExprTuple { elts, .. }) | AnyNodeRef::ExprSet(ast::ExprSet { elts, .. }) => { - if elts.len() > 1 { + if !elts.is_empty() { self.can_have_trailing_comma = true; return TraversalSignal::Skip; } } AnyNodeRef::ExprDict(ast::ExprDict { keys, values, .. }) => { - if keys.len() > 1 || values.len() > 1 { + if !keys.is_empty() || !values.is_empty() { self.can_have_trailing_comma = true; return TraversalSignal::Skip; }