From 2a5d66bb13c584df6d402f2c41a1a34bbe99d45a Mon Sep 17 00:00:00 2001 From: dylwil3 Date: Mon, 8 Dec 2025 12:42:14 -0600 Subject: [PATCH] implement preview: use fluent more often --- .../src/expression/mod.rs | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index feba3ee05c..5a166c2535 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -993,10 +993,35 @@ impl CallChainLayout { } } - if attributes_after_parentheses + u32::from(first_attr_value_parenthesized) < 2 { - CallChainLayout::NonFluent + // Observe that `call_like_count >= attributes_after_parentheses` + // + // Indeed, the latter accumulates only at an attribute expression + // with non-parenthesized, call-like value. After that, we + // immediately set `was_in_call_like` to `true`. Any execution path + // from that code point to the exit or to the next accumulation of + // `attribute_after_parentheses` passes through + // + // ``` + // call_like_count += u32::from(was_in_call_like); + // ``` + // + // and it does so before it could pass through + // `was_in_call_like = false`. + // + // This justifies the name `fluent_layout_more_often_enabled` + // used below. + if is_fluent_layout_more_often_enabled(context) { + if call_like_count + u32::from(first_attr_value_parenthesized) < 2 { + CallChainLayout::NonFluent + } else { + CallChainLayout::Fluent(AttributeState::CallsOrSubscriptsPreceding(call_like_count)) + } } else { - CallChainLayout::Fluent(AttributeState::CallsOrSubscriptsPreceding(call_like_count)) + if attributes_after_parentheses + u32::from(first_attr_value_parenthesized) < 2 { + CallChainLayout::NonFluent + } else { + CallChainLayout::Fluent(AttributeState::CallsOrSubscriptsPreceding(call_like_count)) + } } }