Pass parent to NeedsParentheses (#5708)

This commit is contained in:
Micha Reiser 2023-07-13 08:57:29 +02:00 committed by GitHub
parent 30702c2977
commit 067b2a6ce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
55 changed files with 562 additions and 606 deletions

View file

@ -304,17 +304,6 @@ long_unmergable_string_with_pragma = (
```diff
--- Black
+++ Ruff
@@ -70,8 +70,8 @@
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
- "case, we should just leave it alone." # Third Comment
-)
+ "case, we should just leave it alone."
+) # Third Comment
bad_split_func1(
"But what should happen when code has already "
@@ -143,9 +143,9 @@
)
)
@ -458,8 +447,8 @@ bad_split2 = (
bad_split3 = (
"What if we have inline comments on " # First Comment
"each line of a bad split? In that " # Second Comment
"case, we should just leave it alone."
) # Third Comment
"case, we should just leave it alone." # Third Comment
)
bad_split_func1(
"But what should happen when code has already "

View file

@ -122,11 +122,10 @@ def foo3(list_a, list_b):
- .order_by(User.created_at.desc())
- .with_for_update(key_share=True)
- .all()
- )
+ filter
+ )(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
+ User.created_at.desc()
+ ).with_for_update(key_share=True).all()
+ filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
+ User.created_at.desc()
+ ).with_for_update(key_share=True).all()
)
return results
@ -224,10 +223,10 @@ def foo(list_a, list_b):
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(User.xyz.is_(None)).
# Another comment about the filtering on is_quux goes here.
filter
)(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
User.created_at.desc()
).with_for_update(key_share=True).all()
filter(db.not_(User.is_pending.astext.cast(db.Boolean).is_(True))).order_by(
User.created_at.desc()
).with_for_update(key_share=True).all()
)
return results

View file

@ -398,10 +398,11 @@ last_call()
(*starred,)
{
"id": "1",
@@ -208,24 +208,14 @@
@@ -207,25 +207,15 @@
)
what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
vars_to_remove
)
-)
-result = (
- session.query(models.Customer.id)
- .filter(
@ -409,7 +410,7 @@ last_call()
- )
- .order_by(models.Customer.id.asc())
- .all()
-)
)
-result = (
- session.query(models.Customer.id)
- .filter(
@ -446,7 +447,7 @@ last_call()
async def f():
@@ -248,18 +238,22 @@
@@ -248,18 +238,20 @@
print(*[] or [1])
@ -471,13 +472,11 @@ last_call()
for y in ():
...
-for z in (i for i in (1, 2, 3)):
+for (
+ z
+) in (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
+for z in (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
...
for i in call():
...
@@ -328,13 +322,18 @@
@@ -328,13 +320,18 @@
):
return True
if (
@ -499,7 +498,7 @@ last_call()
^ aaaaaaaa.i << aaaaaaaa.k >> aaaaaaaa.l**aaaaaaaa.m // aaaaaaaa.n
):
return True
@@ -342,7 +341,8 @@
@@ -342,7 +339,8 @@
~aaaaaaaaaaaaaaaa.a
+ aaaaaaaaaaaaaaaa.b
- aaaaaaaaaaaaaaaa.c * aaaaaaaaaaaaaaaa.d @ aaaaaaaaaaaaaaaa.e
@ -767,9 +766,7 @@ for (x,) in (1,), (2,), (3,):
...
for y in ():
...
for (
z
) in (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
for z in (NOT_YET_IMPLEMENTED_generator_key for NOT_YET_IMPLEMENTED_generator_key in []):
...
for i in call():
...

View file

@ -96,18 +96,21 @@ elif unformatted:
```diff
--- Black
+++ Ruff
@@ -5,8 +5,8 @@
@@ -3,10 +3,9 @@
entry_points={
# fmt: off
"console_scripts": [
"foo-bar"
"=foo.bar.:main",
- "foo-bar"
- "=foo.bar.:main",
- # fmt: on
- ] # Includes an formatted indentation.
+ "foo-bar" "=foo.bar.:main",
+ # fmt: on
+ ] # Includes an formatted indentation.
},
)
@@ -27,7 +27,7 @@
@@ -27,7 +26,7 @@
# Regression test for https://github.com/psf/black/issues/3026.
def test_func():
# yapf: disable
@ -116,7 +119,7 @@ elif unformatted:
return True
# yapf: enable
elif b:
@@ -39,10 +39,10 @@
@@ -39,10 +38,10 @@
# Regression test for https://github.com/psf/black/issues/2567.
if True:
# fmt: off
@ -131,7 +134,7 @@ elif unformatted:
else:
print("This will be formatted")
@@ -52,14 +52,12 @@
@@ -52,14 +51,12 @@
async def call(param):
if param:
# fmt: off
@ -149,7 +152,7 @@ elif unformatted:
print("This will be formatted")
@@ -68,13 +66,13 @@
@@ -68,13 +65,13 @@
class Named(t.Protocol):
# fmt: off
@property
@ -165,7 +168,7 @@ elif unformatted:
# fmt: on
@@ -82,6 +80,6 @@
@@ -82,6 +79,6 @@
if x:
return x
# fmt: off
@ -183,8 +186,7 @@ setup(
entry_points={
# fmt: off
"console_scripts": [
"foo-bar"
"=foo.bar.:main",
"foo-bar" "=foo.bar.:main",
# fmt: on
] # Includes an formatted indentation.
},

View file

@ -476,9 +476,9 @@ if (
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py
for user_id in (
set(target_user_ids) - {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}
):
for user_id in set(
target_user_ids
) - {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_set}:
updates.append(UserPresenceState.default(user_id))
# Keeps parenthesized left hand sides

View file

@ -203,7 +203,20 @@ String \"\"\"
"Let's" "start" "with" "a" "simple" "example"
"Let's" "start" "with" "a" "simple" "example" "now repeat after me:" "I am confident" "I am confident" "I am confident" "I am confident" "I am confident"
(
"Let's"
"start"
"with"
"a"
"simple"
"example"
"now repeat after me:"
"I am confident"
"I am confident"
"I am confident"
"I am confident"
"I am confident"
)
(
"Let's"
@ -351,7 +364,20 @@ String \"\"\"
"Let's" 'start' 'with' 'a' 'simple' 'example'
"Let's" 'start' 'with' 'a' 'simple' 'example' 'now repeat after me:' 'I am confident' 'I am confident' 'I am confident' 'I am confident' 'I am confident'
(
"Let's"
'start'
'with'
'a'
'simple'
'example'
'now repeat after me:'
'I am confident'
'I am confident'
'I am confident'
'I am confident'
'I am confident'
)
(
"Let's"

View file

@ -55,11 +55,7 @@ else: # trailing else comment
# trailing else body comment
for (
aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
) in (
anotherVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
): # trailing comment
for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn in anotherVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn: # trailing comment
pass
else:

View file

@ -105,9 +105,7 @@ raise a from OsError(
)
# some comment
raise a from (
aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa
) # some comment
raise a from aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa # some comment
# some comment
raise OsError(

View file

@ -51,9 +51,7 @@ else: # trailing else comment
# trailing else body comment
while (
aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn
): # trailing comment
while aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAndOnAndOnAndOnAndOnAndOnAndOnAndOnAndOn: # trailing comment
pass
else:

View file

@ -82,18 +82,14 @@ with (
with (
(
a # a # comma
),
a, # a # comma
b, # c
): # colon
...
with (
(
a # a # as
) as b, # b # comma
a as b, # a # as # b # comma
c, # c
): # colon
... # body