Skip to content

Commit

Permalink
Fix trailing comma visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Feb 14, 2024
1 parent 25496a8 commit 3d31f69
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/ruff_python_formatter/src/other/f_string_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ impl Format<PyFormatContext<'_>> 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
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3d31f69

Please sign in to comment.