mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
Make BoolOp its own located token (#3265)
This commit is contained in:
parent
470e1c1754
commit
061495a9eb
19 changed files with 355 additions and 301 deletions
|
@ -178,7 +178,7 @@ instruction()#comment with bad spacing
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -72,14 +72,20 @@
|
||||
@@ -72,7 +72,11 @@
|
||||
body,
|
||||
parameters.children[-1], # )2
|
||||
]
|
||||
|
@ -190,21 +190,8 @@ instruction()#comment with bad spacing
|
|||
+ ] # type: ignore
|
||||
if (
|
||||
self._proc is not None
|
||||
- # has the child process finished?
|
||||
- and self._returncode is None
|
||||
- # the child process has finished, but the
|
||||
+ and # has the child process finished?
|
||||
+ self._returncode
|
||||
+ is None
|
||||
+ and # the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
- and self._proc.poll() is None
|
||||
+ self._proc.poll()
|
||||
+ is None
|
||||
):
|
||||
pass
|
||||
# no newline before or after
|
||||
@@ -103,35 +109,35 @@
|
||||
# has the child process finished?
|
||||
@@ -103,35 +107,35 @@
|
||||
############################################################################
|
||||
|
||||
call2(
|
||||
|
@ -219,10 +206,8 @@ instruction()#comment with bad spacing
|
|||
"""
|
||||
short
|
||||
""",
|
||||
- # yup
|
||||
- arg3=True,
|
||||
+ arg3=# yup
|
||||
+ True,
|
||||
# yup
|
||||
arg3=True,
|
||||
)
|
||||
- lcomp = [
|
||||
- element for element in collection if element is not None # yup # yup # right
|
||||
|
@ -256,7 +241,7 @@ instruction()#comment with bad spacing
|
|||
]
|
||||
while True:
|
||||
if False:
|
||||
@@ -167,7 +173,7 @@
|
||||
@@ -167,7 +171,7 @@
|
||||
#######################
|
||||
|
||||
|
||||
|
@ -351,13 +336,11 @@ def inline_comments_in_brackets_ruin_everything():
|
|||
] # type: ignore
|
||||
if (
|
||||
self._proc is not None
|
||||
and # has the child process finished?
|
||||
self._returncode
|
||||
is None
|
||||
and # the child process has finished, but the
|
||||
# has the child process finished?
|
||||
and self._returncode is None
|
||||
# the child process has finished, but the
|
||||
# transport hasn't been notified yet?
|
||||
self._proc.poll()
|
||||
is None
|
||||
and self._proc.poll() is None
|
||||
):
|
||||
pass
|
||||
# no newline before or after
|
||||
|
@ -389,8 +372,8 @@ short
|
|||
"""
|
||||
short
|
||||
""",
|
||||
arg3=# yup
|
||||
True,
|
||||
# yup
|
||||
arg3=True,
|
||||
)
|
||||
lcomp = [element for element in collection if element is not None] # yup # yup # right
|
||||
lcomp2 = [
|
||||
|
|
|
@ -77,30 +77,6 @@ def func():
|
|||
]
|
||||
# Capture each of the exceptions in the MultiError along with each of their causes and contexts
|
||||
if isinstance(exc_value, MultiError):
|
||||
@@ -26,9 +27,9 @@
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
- # copy the set of _seen exceptions so that duplicates
|
||||
+ _seen=# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
- _seen=set(_seen),
|
||||
+ set(_seen),
|
||||
)
|
||||
# This should be left alone (after)
|
||||
)
|
||||
@@ -39,9 +40,9 @@
|
||||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
- # copy the set of _seen exceptions so that duplicates
|
||||
+ _seen=# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
- _seen=set(_seen),
|
||||
+ set(_seen),
|
||||
)
|
||||
|
||||
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -135,9 +111,9 @@ def func():
|
|||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
_seen=# copy the set of _seen exceptions so that duplicates
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
set(_seen),
|
||||
_seen=set(_seen),
|
||||
)
|
||||
# This should be left alone (after)
|
||||
)
|
||||
|
@ -148,9 +124,9 @@ def func():
|
|||
limit=limit,
|
||||
lookup_lines=lookup_lines,
|
||||
capture_locals=capture_locals,
|
||||
_seen=# copy the set of _seen exceptions so that duplicates
|
||||
# copy the set of _seen exceptions so that duplicates
|
||||
# shared between sub-exceptions are not omitted
|
||||
set(_seen),
|
||||
_seen=set(_seen),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -204,15 +204,9 @@ class C:
|
|||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
@@ -22,133 +23,155 @@
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
+ and # Rule 2
|
||||
+ i % 3
|
||||
+ == 0
|
||||
@@ -25,11 +26,8 @@
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
- while (
|
||||
- # Just a comment
|
||||
|
@ -224,13 +218,9 @@ class C:
|
|||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
- # Only send the first n items.
|
||||
- items=items[:num_items]
|
||||
+ items=# Only send the first n items.
|
||||
+ items[:num_items]
|
||||
@@ -39,116 +37,140 @@
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
- return (
|
||||
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
|
@ -460,7 +450,7 @@ class C:
|
|||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
@@ -161,9 +184,8 @@
|
||||
@@ -161,9 +183,8 @@
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
|
@ -502,9 +492,8 @@ class C:
|
|||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
and # Rule 2
|
||||
i % 3
|
||||
== 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while # Just a comment
|
||||
call():
|
||||
|
@ -514,8 +503,8 @@ class C:
|
|||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
items=# Only send the first n items.
|
||||
items[:num_items]
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
return 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
|
|
|
@ -204,15 +204,9 @@ class C:
|
|||
)
|
||||
self.assertEqual(
|
||||
unstyle(str(report)),
|
||||
@@ -22,133 +23,155 @@
|
||||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
- # Rule 2
|
||||
- and i % 3 == 0
|
||||
+ and # Rule 2
|
||||
+ i % 3
|
||||
+ == 0
|
||||
@@ -25,11 +26,8 @@
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
- while (
|
||||
- # Just a comment
|
||||
|
@ -224,13 +218,9 @@ class C:
|
|||
print(i)
|
||||
xxxxxxxxxxxxxxxx = Yyyy2YyyyyYyyyyy(
|
||||
push_manager=context.request.resource_manager,
|
||||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
- # Only send the first n items.
|
||||
- items=items[:num_items]
|
||||
+ items=# Only send the first n items.
|
||||
+ items[:num_items]
|
||||
@@ -39,116 +37,140 @@
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
- return (
|
||||
- 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
|
@ -460,7 +450,7 @@ class C:
|
|||
"Not what we expected and the message is too long to fit in one line"
|
||||
" because it's too long"
|
||||
)
|
||||
@@ -161,9 +184,8 @@
|
||||
@@ -161,9 +183,8 @@
|
||||
8 STORE_ATTR 0 (x)
|
||||
10 LOAD_CONST 0 (None)
|
||||
12 RETURN_VALUE
|
||||
|
@ -502,9 +492,8 @@ class C:
|
|||
if (
|
||||
# Rule 1
|
||||
i % 2 == 0
|
||||
and # Rule 2
|
||||
i % 3
|
||||
== 0
|
||||
# Rule 2
|
||||
and i % 3 == 0
|
||||
):
|
||||
while # Just a comment
|
||||
call():
|
||||
|
@ -514,8 +503,8 @@ class C:
|
|||
max_items_to_push=num_items,
|
||||
batch_size=Yyyy2YyyyYyyyyYyyy.FULL_SIZE,
|
||||
).push(
|
||||
items=# Only send the first n items.
|
||||
items[:num_items]
|
||||
# Only send the first n items.
|
||||
items=items[:num_items]
|
||||
)
|
||||
return 'Utterly failed doctest test for %s\n File "%s", line %s, in %s\n\n%s'
|
||||
% (test.name, test.filename, lineno, lname, err)
|
||||
|
|
|
@ -394,25 +394,8 @@ d={'a':1,
|
|||
# fmt: on
|
||||
)
|
||||
|
||||
@@ -200,8 +213,8 @@
|
||||
xxxxxx_xxxxxx=2,
|
||||
xxxxxx_xxxxx_xxxxxxxx=70,
|
||||
xxxxxx_xxxxxx_xxxxx=True,
|
||||
- # fmt: off
|
||||
- xxxxxxx_xxxxxxxxxxxx={
|
||||
+ xxxxxxx_xxxxxxxxxxxx=# fmt: off
|
||||
+ {
|
||||
"xxxxxxxx": {
|
||||
"xxxxxx": False,
|
||||
"xxxxxxx": False,
|
||||
@@ -213,12 +226,11 @@
|
||||
"xxxx_xxxxxx": "xxxxxx",
|
||||
},
|
||||
},
|
||||
- # fmt: on
|
||||
- xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
|
||||
+ xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=# fmt: on
|
||||
+ 5,
|
||||
@@ -217,8 +230,7 @@
|
||||
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
|
||||
)
|
||||
# fmt: off
|
||||
-yield 'hello'
|
||||
|
@ -643,8 +626,8 @@ cfg.rule(
|
|||
xxxxxx_xxxxxx=2,
|
||||
xxxxxx_xxxxx_xxxxxxxx=70,
|
||||
xxxxxx_xxxxxx_xxxxx=True,
|
||||
xxxxxxx_xxxxxxxxxxxx=# fmt: off
|
||||
{
|
||||
# fmt: off
|
||||
xxxxxxx_xxxxxxxxxxxx={
|
||||
"xxxxxxxx": {
|
||||
"xxxxxx": False,
|
||||
"xxxxxxx": False,
|
||||
|
@ -656,8 +639,8 @@ cfg.rule(
|
|||
"xxxx_xxxxxx": "xxxxxx",
|
||||
},
|
||||
},
|
||||
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=# fmt: on
|
||||
5,
|
||||
# fmt: on
|
||||
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
|
||||
)
|
||||
# fmt: off
|
||||
yield "hello"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue