Properly group assignment targets (#5728)

This commit is contained in:
Micha Reiser 2023-07-13 16:00:49 +02:00 committed by GitHub
parent f48ab2d621
commit 5dd5ee0c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 15 deletions

View file

@ -443,6 +443,10 @@ impl<'input> PreorderVisitor<'input> for CanOmitOptionalParenthesesVisitor<'inpu
}
fn has_parentheses(expr: &Expr, source: &str) -> bool {
has_own_parentheses(expr) || is_expression_parenthesized(AnyNodeRef::from(expr), source)
}
pub(crate) const fn has_own_parentheses(expr: &Expr) -> bool {
matches!(
expr,
Expr::Dict(_)
@ -454,7 +458,7 @@ fn has_parentheses(expr: &Expr, source: &str) -> bool {
| Expr::DictComp(_)
| Expr::Call(_)
| Expr::Subscript(_)
) || is_expression_parenthesized(AnyNodeRef::from(expr), source)
)
}
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]