mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 03:45:14 +00:00
Preserve parentheses around partial call chains (#7109)
This commit is contained in:
parent
7be28a38c5
commit
ece30e7c69
4 changed files with 207 additions and 38 deletions
|
@ -630,20 +630,21 @@ impl CallChainLayout {
|
|||
loop {
|
||||
match expr {
|
||||
ExpressionRef::Attribute(ast::ExprAttribute { value, .. }) => {
|
||||
expr = ExpressionRef::from(value.as_ref());
|
||||
// ```
|
||||
// f().g
|
||||
// ^^^ value
|
||||
// data[:100].T
|
||||
// ^^^^^^^^^^ value
|
||||
// ```
|
||||
if matches!(value.as_ref(), Expr::Call(_) | Expr::Subscript(_)) {
|
||||
attributes_after_parentheses += 1;
|
||||
} else if is_expression_parenthesized(expr, source) {
|
||||
if is_expression_parenthesized(value.into(), source) {
|
||||
// `(a).b`. We preserve these parentheses so don't recurse
|
||||
attributes_after_parentheses += 1;
|
||||
break;
|
||||
} else if matches!(value.as_ref(), Expr::Call(_) | Expr::Subscript(_)) {
|
||||
attributes_after_parentheses += 1;
|
||||
}
|
||||
|
||||
expr = ExpressionRef::from(value.as_ref());
|
||||
}
|
||||
// ```
|
||||
// f()
|
||||
|
@ -666,9 +667,11 @@ impl CallChainLayout {
|
|||
if is_expression_parenthesized(expr, source) {
|
||||
attributes_after_parentheses += 1;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// We preserve these parentheses so don't recurse
|
||||
if is_expression_parenthesized(expr, source) {
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue