Don't "flatten" nested if expressions when formatting (#6996)

This commit is contained in:
Victor Hugo Gomes 2023-08-30 01:11:58 -03:00 committed by GitHub
parent b404e54f33
commit 31947af6a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 305 additions and 25 deletions

View file

@ -136,6 +136,15 @@ def something():
for some_boolean_variable in some_iterable
)
@@ -86,5 +78,7 @@
clone._iterable_class = (
NamedValuesListIterable
if named
- else FlatValuesListIterable if flat else ValuesListIterable
+ else FlatValuesListIterable
+ if flat
+ else ValuesListIterable
)
```
## Ruff Output
@ -221,7 +230,9 @@ def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable if flat else ValuesListIterable
else FlatValuesListIterable
if flat
else ValuesListIterable
)
```

View file

@ -45,6 +45,75 @@ d1 = [
("b") else # 2
("c")
]
e1 = (
a
if True # 1
else b
if False # 2
else c
)
# Flattening nested if-expressions.
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
(NamedValuesListIterable
if named
else FlatValuesListIterable)
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else (FlatValuesListIterable
if flat
else ValuesListIterable)
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable(1,)
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable + FlatValuesListIterable + FlatValuesListIterable + FlatValuesListIterable
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else (FlatValuesListIterable + FlatValuesListIterable + FlatValuesListIterable + FlatValuesListIterable
if flat
else ValuesListIterable)
)
```
## Output
@ -96,6 +165,81 @@ d1 = [
# 2
else ("c")
]
e1 = (
a
if True # 1
else b
if False # 2
else c
)
# Flattening nested if-expressions.
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
(NamedValuesListIterable if named else FlatValuesListIterable)
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else (FlatValuesListIterable if flat else ValuesListIterable)
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable(
1,
)
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else FlatValuesListIterable
+ FlatValuesListIterable
+ FlatValuesListIterable
+ FlatValuesListIterable
if flat
else ValuesListIterable
)
def something():
clone._iterable_class = (
NamedValuesListIterable
if named
else (
FlatValuesListIterable
+ FlatValuesListIterable
+ FlatValuesListIterable
+ FlatValuesListIterable
if flat
else ValuesListIterable
)
)
```