revert using fluent more often for now

This commit is contained in:
dylwil3 2025-12-12 08:52:02 -06:00
parent 43d9566d4e
commit cb73474718
12 changed files with 26 additions and 180 deletions

View File

@ -199,7 +199,6 @@ impl NeedsParentheses for ExprAttribute {
self.into(), self.into(),
context.comments().ranges(), context.comments().ranges(),
context.source(), context.source(),
context
), ),
CallChainLayout::Fluent(_) CallChainLayout::Fluent(_)
) { ) {

View File

@ -91,7 +91,6 @@ impl NeedsParentheses for ExprCall {
self.into(), self.into(),
context.comments().ranges(), context.comments().ranges(),
context.source(), context.source(),
context
), ),
CallChainLayout::Fluent(_) CallChainLayout::Fluent(_)
) { ) {

View File

@ -96,7 +96,6 @@ impl NeedsParentheses for ExprSubscript {
self.into(), self.into(),
context.comments().ranges(), context.comments().ranges(),
context.source(), context.source(),
context
), ),
CallChainLayout::Fluent(_) CallChainLayout::Fluent(_)
) { ) {

View File

@ -19,9 +19,7 @@ use crate::expression::parentheses::{
optional_parentheses, parenthesized, optional_parentheses, parenthesized,
}; };
use crate::prelude::*; use crate::prelude::*;
use crate::preview::{ use crate::preview::is_hug_parens_with_braces_and_square_brackets_enabled;
is_fluent_layout_more_often_enabled, is_hug_parens_with_braces_and_square_brackets_enabled,
};
mod binary_like; mod binary_like;
pub(crate) mod expr_attribute; pub(crate) mod expr_attribute;
@ -963,9 +961,6 @@ impl CallChainLayout {
mut expr: ExprRef, mut expr: ExprRef,
comment_ranges: &CommentRanges, comment_ranges: &CommentRanges,
source: &str, source: &str,
// This can be deleted once the preview style
// is stabilized
context: &PyFormatContext,
) -> Self { ) -> Self {
// Count of attribute values which are called or // Count of attribute values which are called or
// subscripted, after the leftmost parenthesized // subscripted, after the leftmost parenthesized
@ -1039,13 +1034,7 @@ impl CallChainLayout {
} }
} }
let threshold = if is_fluent_layout_more_often_enabled(context) { if computed_attribute_values_after_parentheses + u32::from(root_value_parenthesized) < 2 {
call_like_count + u32::from(root_value_parenthesized)
} else {
computed_attribute_values_after_parentheses + u32::from(root_value_parenthesized)
};
if threshold < 2 {
CallChainLayout::NonFluent CallChainLayout::NonFluent
} else { } else {
CallChainLayout::Fluent(AttributeState::CallsOrSubscriptsPreceding(call_like_count)) CallChainLayout::Fluent(AttributeState::CallsOrSubscriptsPreceding(call_like_count))
@ -1066,7 +1055,6 @@ impl CallChainLayout {
item.into(), item.into(),
f.context().comments().ranges(), f.context().comments().ranges(),
f.context().source(), f.context().source(),
f.context(),
) )
} else { } else {
CallChainLayout::NonFluent CallChainLayout::NonFluent

View File

@ -66,10 +66,3 @@ pub(crate) const fn is_parenthesize_lambda_bodies_enabled(context: &PyFormatCont
pub(crate) const fn is_fluent_layout_split_first_call_enabled(context: &PyFormatContext) -> bool { pub(crate) const fn is_fluent_layout_split_first_call_enabled(context: &PyFormatContext) -> bool {
context.is_preview() context.is_preview()
} }
/// Returns `true` if the
/// [`fluent_layout_more_often`](https://github.com/astral-sh/ruff/pull/21369) preview
/// style is enabled.
pub(crate) const fn is_fluent_layout_more_often_enabled(context: &PyFormatContext) -> bool {
context.is_preview()
}

View File

@ -228,7 +228,7 @@ class Random:
} }
{ {
@@ -139,17 +133,16 @@ @@ -139,17 +133,17 @@
class Random: class Random:
def func(): def func():
@ -244,8 +244,9 @@ class Random:
- "actionTimestamp": ( - "actionTimestamp": (
- Timestamp(seconds=1530584000, nanos=0).ToJsonString() - Timestamp(seconds=1530584000, nanos=0).ToJsonString()
- ), - ),
+ "actionTimestamp": Timestamp(seconds=1530584000, nanos=0) + "actionTimestamp": Timestamp(
+ .ToJsonString(), + seconds=1530584000, nanos=0
+ ).ToJsonString(),
} }
}, },
- } - }
@ -398,8 +399,9 @@ class Random:
"timestamp": 1234, "timestamp": 1234,
"latitude": 1, "latitude": 1,
"longitude": 2, "longitude": 2,
"actionTimestamp": Timestamp(seconds=1530584000, nanos=0) "actionTimestamp": Timestamp(
.ToJsonString(), seconds=1530584000, nanos=0
).ToJsonString(),
} }
}, },
}) })

View File

@ -414,12 +414,12 @@ a = b if """
+ """cow + """cow
+moos""" +moos"""
+} +}
[
"""cow
+moos"""
+]
+[ +[
+ """cow + """cow
+moos"""
+]
[
"""cow
moos""", moos""",
@@ -206,7 +245,9 @@ @@ -206,7 +245,9 @@
"c" "c"

View File

@ -2914,19 +2914,6 @@ def length_rst_in_section():
```diff ```diff
--- Stable --- Stable
+++ Preview +++ Preview
@@ -683,9 +683,9 @@
... self._df.filter(pl.col(col).str.starts_with(c))
... for c in sorted(
... set(
- ... df.select(
- ... pl.col(col).str.slice(0, 1)
- ... ).to_series()
+ ... df
+ ... .select(pl.col(col).str.slice(0, 1))
+ ... .to_series()
... )
... )
... ]
@@ -700,9 +700,11 @@ @@ -700,9 +700,11 @@
Examples Examples

View File

@ -429,20 +429,3 @@ variable = (
.first_method("some string") .first_method("some string")
) )
``` ```
## Preview changes
```diff
--- Stable
+++ Preview
@@ -171,7 +171,8 @@
if (
(
something # a comment
- ).first_method("some string") # second comment
+ )
+ .first_method("some string") # second comment
):
pass
```

View File

@ -198,24 +198,7 @@ response = await sync_to_async(
```diff ```diff
--- Stable --- Stable
+++ Preview +++ Preview
@@ -18,10 +18,14 @@ @@ -62,9 +62,9 @@
).casefold(1)
ct_match = (
- unicodedata.normalize("NFKC", s1).casefold(
+ unicodedata
+ .normalize("NFKC", s1)
+ .casefold(
# foo
)
- == unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold(
+ == unicodedata
+ .normalize("NFKCNFKCNFKCNFKCNFKC", s2)
+ .casefold(
# foo
)
)
@@ -62,9 +66,9 @@
1 1
}.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold() }.unicodedata.normalize("NFKCNFKCNFKCNFKCNFKC", s2).casefold()

View File

@ -472,26 +472,7 @@ max_message_id = (
```diff ```diff
--- Stable --- Stable
+++ Preview +++ Preview
@@ -4,11 +4,13 @@ @@ -21,7 +21,8 @@
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
).a(aaaa)
-raise OsError(
- "sökdjffffsldkfjlhsakfjhalsökafhsöfdahsödfjösaaksjdllllllllllllll"
-) from a.aaaaa(
- aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
-).a(aaaa)
+raise OsError("sökdjffffsldkfjlhsakfjhalsökafhsöfdahsödfjösaaksjdllllllllllllll") from (
+ a
+ .aaaaa(
+ aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
+ )
+ .a(aaaa)
+)
a1 = Blog.objects.filter(entry__headline__contains="Lennon").filter(
entry__pub_date__year=2008
@@ -21,7 +23,8 @@
) )
raise OsError("") from ( raise OsError("") from (
@ -501,7 +482,7 @@ max_message_id = (
entry__headline__contains="Lennon", entry__headline__contains="Lennon",
) )
.filter( .filter(
@@ -33,7 +36,8 @@ @@ -33,7 +34,8 @@
) )
raise OsError("sökdjffffsldkfjlhsakfjhalsökafhsöfdahsödfjösaaksjdllllllllllllll") from ( raise OsError("sökdjffffsldkfjlhsakfjhalsökafhsöfdahsödfjösaaksjdllllllllllllll") from (
@ -511,7 +492,7 @@ max_message_id = (
entry__headline__contains="Lennon", entry__headline__contains="Lennon",
) )
.filter( .filter(
@@ -46,7 +50,8 @@ @@ -46,7 +48,8 @@
# Break only after calls and indexing # Break only after calls and indexing
b1 = ( b1 = (
@ -521,7 +502,7 @@ max_message_id = (
.filter( .filter(
models.Customer.account_id == account_id, models.Customer.email == email_address models.Customer.account_id == account_id, models.Customer.email == email_address
) )
@@ -54,7 +59,8 @@ @@ -54,7 +57,8 @@
) )
b2 = ( b2 = (
@ -531,17 +512,8 @@ max_message_id = (
entry__headline__contains="Lennon", entry__headline__contains="Lennon",
) )
.limit_results[:10] .limit_results[:10]
@@ -65,12 +71,15 @@ @@ -70,7 +74,8 @@
).filter(
# Nested call chains
c1 = (
- Blog.objects.filter(
+ Blog.objects
+ .filter(
entry__headline__contains="Lennon",
- ).filter(
+ )
+ .filter(
entry__pub_date__year=2008, entry__pub_date__year=2008,
) )
- + Blog.objects.filter( - + Blog.objects.filter(
@ -550,7 +522,7 @@ max_message_id = (
entry__headline__contains="McCartney", entry__headline__contains="McCartney",
) )
.limit_results[:10] .limit_results[:10]
@@ -89,19 +98,23 @@ @@ -89,7 +94,8 @@
d11 = x.e().e().e() # d11 = x.e().e().e() #
d12 = x.e().e().e() # d12 = x.e().e().e() #
d13 = ( d13 = (
@ -560,14 +532,7 @@ max_message_id = (
.e() .e()
.e() .e()
) )
@@ -101,7 +107,8 @@
# Doesn't fit, default
d2 = (
- x.e().esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkfsdddd() #
+ x
+ .e()
+ .esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkfsdddd() #
)
# Doesn't fit, fluent style # Doesn't fit, fluent style
d3 = ( d3 = (
@ -577,32 +542,7 @@ max_message_id = (
.esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk() .esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk()
.esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk() .esadjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk()
) )
@@ -199,16 +212,21 @@ @@ -218,7 +225,8 @@
(
(
- df1_aaaaaaaaaaaa.merge().groupby(
+ df1_aaaaaaaaaaaa
+ .merge()
+ .groupby(
1,
)
- ).sum()
+ )
+ .sum()
)
(
(
- df1_aaaaaaaaaaaa.merge().groupby(
+ df1_aaaaaaaaaaaa
+ .merge()
+ .groupby(
1,
)
)
@@ -218,17 +236,20 @@
( (
( (
@ -612,11 +552,7 @@ max_message_id = (
.groupby( .groupby(
1, 1,
) )
.bar() @@ -228,7 +236,8 @@
- ).sum()
+ )
+ .sum()
)
( (
( (

View File

@ -538,33 +538,10 @@ x = (
Both the stable and preview formatting are variants of something Both the stable and preview formatting are variants of something
called a **fluent layout**. called a **fluent layout**.
In general, this preview style differs from the stable style in the In general, this preview style differs from the stable style
following two ways: only at the first attribute that precedes
1. In the case where a fluent layout is applied, the preview formatting
differs from the stable formatting only at the first attribute that precedes
a call or subscript. The preview formatting breaks _before_ this attribute, a call or subscript. The preview formatting breaks _before_ this attribute,
while the stable formatting breaks _after_ the call or subscript. while the stable formatting breaks _after_ the call or subscript.
2. When `preview` is enabled, the fluent layout will be used slightly more often, as we explain below.
To explain point (2), we need to explain the heuristic used for deciding
whether to apply a fluent layout. In stable, the heuristic is essentially
to apply fluent formatting in the following situations:
- A parenthesized, call, or subscript expression is followed by at least one attribute that is called or subscripted, excluding the last attribute in the chain, or
- A non-attribute expression is followed by at least two attributes that
are called or subscripted, excluding the last attribute in the chain
In `preview` the heuristic is identical except that we do not exclude the
last attribute in the chain from consideration.
For example, with `line-length = 8`, we have:
```python
x = a[0].b().c # formatted to fluent with and without preview
x = a.b().c().d # formatted to fluent with and without preview
x = a.d.b().c() # formatted to fluent only in preview
```
## Sorting imports ## Sorting imports