Fix invalid syntax for binary expression in unary op (#5370)

This commit is contained in:
Micha Reiser 2023-06-29 08:09:26 +02:00 committed by GitHub
parent 38189ed913
commit 955e9ef821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 200 additions and 116 deletions

View file

@ -147,7 +147,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
an_element_with_a_long_value = calls() or more_calls() and more() # type: bool
tup = (
@@ -100,19 +98,35 @@
@@ -100,19 +98,32 @@
)
c = call(
@ -169,10 +169,7 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
-AAAAAAAAAAAAA = [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA # type: ignore
+AAAAAAAAAAAAA = (
+ [AAAAAAAAAAAAA]
+ + SHARED_AAAAAAAAAAAAA
+ + USER_AAAAAAAAAAAAA
+ + AAAAAAAAAAAAA
+ [AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA
+) # type: ignore
call_to_some_function_asdf(
@ -308,10 +305,7 @@ def func(
result = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # aaa
AAAAAAAAAAAAA = (
[AAAAAAAAAAAAA]
+ SHARED_AAAAAAAAAAAAA
+ USER_AAAAAAAAAAAAA
+ AAAAAAAAAAAAA
[AAAAAAAAAAAAA] + SHARED_AAAAAAAAAAAAA + USER_AAAAAAAAAAAAA + AAAAAAAAAAAAA
) # type: ignore
call_to_some_function_asdf(

View file

@ -274,11 +274,20 @@ last_call()
Name
None
True
@@ -30,33 +31,39 @@
@@ -23,40 +24,46 @@
1 >> v2
1 % finished
1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8
-((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8)
+(1 + v2 - (v3 * 4)) ^ (5**v6 / 7 // 8)
not great
~great
+value
-1
~int and not v1 ^ 123 + v2 | True
(~int) and (not ((v1 ^ (123 + v2)) | True))
-(~int) and (not ((v1 ^ (123 + v2)) | True))
-+(really ** -(confusing ** ~(operator**-precedence)))
+(~int) and (not (v1 ^ (123 + v2) | True))
++really ** -confusing ** ~operator**-precedence
flags & ~select.EPOLLIN and waiters.write_task is not None
-lambda arg: None
@ -638,13 +647,13 @@ v1 << 2
1 >> v2
1 % finished
1 + v2 - v3 * 4 ^ 5**v6 / 7 // 8
((1 + v2) - (v3 * 4)) ^ (((5**v6) / 7) // 8)
(1 + v2 - (v3 * 4)) ^ (5**v6 / 7 // 8)
not great
~great
+value
-1
~int and not v1 ^ 123 + v2 | True
(~int) and (not ((v1 ^ (123 + v2)) | True))
(~int) and (not (v1 ^ (123 + v2) | True))
+really ** -confusing ** ~operator**-precedence
flags & ~select.EPOLLIN and waiters.write_task is not None
lambda x: True

View file

@ -202,11 +202,11 @@ d={'a':1,
#!/usr/bin/env python3
-import asyncio
-import sys
-
-from third_party import X, Y, Z
+NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImport
-from third_party import X, Y, Z
-
-from library import some_connection, some_decorator
+NOT_YET_IMPLEMENTED_StmtImportFrom
@ -306,7 +306,7 @@ d={'a':1,
h: str = "",
i: str = r"",
):
@@ -64,55 +86,55 @@
@@ -64,55 +86,54 @@
something = {
# fmt: off
@ -327,8 +327,7 @@ d={'a':1,
+ "some big and",
+ "complex subscript",
+ # fmt: on
+ goes
+ + here,
+ goes + here,
+ andhere,
+ )
]
@ -382,7 +381,7 @@ d={'a':1,
# fmt: on
@@ -133,10 +155,10 @@
@@ -133,10 +154,10 @@
"""Another known limitation."""
# fmt: on
# fmt: off
@ -397,7 +396,7 @@ d={'a':1,
# fmt: on
# fmt: off
# ...but comments still get reformatted even though they should not be
@@ -151,12 +173,10 @@
@@ -151,12 +172,10 @@
ast_args.kw_defaults,
parameters,
implicit_default=True,
@ -412,17 +411,16 @@ d={'a':1,
# fmt: on
_type_comment_re = re.compile(
r"""
@@ -179,7 +199,8 @@
@@ -179,7 +198,7 @@
$
""",
# fmt: off
- re.MULTILINE|re.VERBOSE
+ re.MULTILINE
+ | re.VERBOSE,
+ re.MULTILINE | re.VERBOSE,
# fmt: on
)
@@ -217,8 +238,7 @@
@@ -217,8 +236,7 @@
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
)
# fmt: off
@ -538,8 +536,7 @@ def subscriptlist():
"some big and",
"complex subscript",
# fmt: on
goes
+ here,
goes + here,
andhere,
)
]
@ -640,8 +637,7 @@ def long_lines():
$
""",
# fmt: off
re.MULTILINE
| re.VERBOSE,
re.MULTILINE | re.VERBOSE,
# fmt: on
)

View file

@ -111,14 +111,14 @@ def __await__(): return (yield)
#!/usr/bin/env python3
-import asyncio
-import sys
-
-from third_party import X, Y, Z
+NOT_YET_IMPLEMENTED_StmtImport
+NOT_YET_IMPLEMENTED_StmtImport
-from library import some_connection, some_decorator
-from third_party import X, Y, Z
+NOT_YET_IMPLEMENTED_StmtImportFrom
-from library import some_connection, some_decorator
-
-f"trigger 3.6 mode"
+NOT_YET_IMPLEMENTED_StmtImportFrom
+NOT_YET_IMPLEMENTED_ExprJoinedStr
@ -215,17 +215,7 @@ def __await__(): return (yield)
)
_type_comment_re = re.compile(
r"""
@@ -118,7 +124,8 @@
)
$
""",
- re.MULTILINE | re.VERBOSE,
+ re.MULTILINE
+ | re.VERBOSE,
)
@@ -135,14 +142,8 @@
@@ -135,14 +141,8 @@
a,
**kwargs,
) -> A:
@ -373,8 +363,7 @@ def long_lines():
)
$
""",
re.MULTILINE
| re.VERBOSE,
re.MULTILINE | re.VERBOSE,
)

View file

@ -115,12 +115,13 @@ x[
ham[lower + offset : upper + offset]
slice[::, ::]
@@ -50,10 +50,14 @@
@@ -49,11 +49,14 @@
slice[
# A
1
- 1
- + 2 :
+ + 2 :
+ 1 + 2 :
# B
- 3 :
+ 3 :
@ -189,8 +190,7 @@ slice[
slice[
# A
1
+ 2 :
1 + 2 :
# B
3 :
# C

View file

@ -16,6 +16,19 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/expression
b
)
(
# leading left most comment
aaaaaaaa
+ # trailing operator comment
# leading b comment
b # trailing b comment
# trailing b ownline comment
+ # trailing second operator comment
# leading c comment
c # trailing c comment
# trailing own line comment
)
# Black breaks the right side first for the following expressions:
aaaaaaaaaaaaaa + caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal(argument1, argument2, argument3)
@ -204,7 +217,8 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}:
```py
(
aaaaaaaa
+ b # trailing operator comment # trailing right comment
+ # trailing operator comment
b # trailing right comment
)
@ -215,6 +229,19 @@ for user_id in set(target_user_ids) - {u.user_id for u in updates}:
b
)
(
# leading left most comment
aaaaaaaa
+ # trailing operator comment
# leading b comment
b # trailing b comment
# trailing b ownline comment
+ # trailing second operator comment
# leading c comment
c # trailing c comment
# trailing own line comment
)
# Black breaks the right side first for the following expressions:
aaaaaaaaaaaaaa + caaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal(
@ -269,8 +296,7 @@ not (aaaaaaaaaaaaaa + {NOT_IMPLEMENTED_set_value for value in NOT_IMPLEMENTED_se
# leading comment
(
# comment
content
+ b
content + b
)
@ -417,8 +443,7 @@ if (
&
(
# comment
a
+ b
a + b
)
):
...
@ -433,8 +458,7 @@ if (
]
&
# comment
a
+ b
a + b
):
...

View file

@ -142,6 +142,10 @@ if (
if not \
a:
pass
# Regression: https://github.com/astral-sh/ruff/issues/5338
if a and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
...
```
## Output
@ -253,10 +257,8 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & (
pass
if (
not (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
)
not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
):
pass
@ -295,6 +297,14 @@ if (
if not a:
pass
# Regression: https://github.com/astral-sh/ruff/issues/5338
if (
a
and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
):
...
```

View file

@ -125,8 +125,7 @@ f(
f(
this_is_a_very_long_argument_asökdhflakjslaslhfdlaffahflahsöfdhasägporejfäalkdsjäfalisjäfdlkasjd,
these_arguments_have_values_that_need_to_break_because_they_are_too_long1=(
100000
- 100000000000
100000 - 100000000000
),
these_arguments_have_values_that_need_to_break_because_they_are_too_long2="akshfdlakjsdfad"
+ "asdfasdfa",

View file

@ -38,6 +38,9 @@ class Test((Aaaa)):
class Test(aaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbb + cccccccccccccccccccccccc + dddddddddddddddddddddd + eeeeeeeee, ffffffffffffffffff, gggggggggggggggggg):
pass
class Test(aaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccc + dddddddddddddddddddddd + eeeeeeeee, ffffffffffffffffff, gggggggggggggggggg):
pass
class Test(Aaaa): # trailing comment
pass
```
@ -88,6 +91,17 @@ class Test(
pass
class Test(
aaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccc
+ dddddddddddddddddddddd
+ eeeeeeeee,
ffffffffffffffffff,
gggggggggggggggggg,
):
pass
class Test(Aaaa): # trailing comment
pass
```

View file

@ -114,8 +114,7 @@ with a: # should remove brackets
# WithItem allow the `aa + bb` content expression to be wrapped
with (
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
) as c,
):
...