mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-24 13:33:50 +00:00
Update Black tests (#6618)
## Summary Pulls in some tests that we previously couldn't support ## Test Plan `cargo test`
This commit is contained in:
parent
12f3c4c931
commit
d0b8e4f701
8 changed files with 778 additions and 5 deletions
|
@ -0,0 +1,247 @@
|
|||
---
|
||||
source: crates/ruff_python_formatter/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_38/pep_572_remove_parens.py
|
||||
---
|
||||
## Input
|
||||
|
||||
```py
|
||||
if (foo := 0):
|
||||
pass
|
||||
|
||||
if (foo := 1):
|
||||
pass
|
||||
|
||||
if (y := 5 + 5):
|
||||
pass
|
||||
|
||||
y = (x := 0)
|
||||
|
||||
y += (x := 0)
|
||||
|
||||
(y := 5 + 5)
|
||||
|
||||
test: int = (test2 := 2)
|
||||
|
||||
a, b = (test := (1, 2))
|
||||
|
||||
# see also https://github.com/psf/black/issues/2139
|
||||
assert (foo := 42 - 12)
|
||||
|
||||
foo(x=(y := f(x)))
|
||||
|
||||
|
||||
def foo(answer=(p := 42)):
|
||||
...
|
||||
|
||||
|
||||
def foo2(answer: (p := 42) = 5):
|
||||
...
|
||||
|
||||
|
||||
lambda: (x := 1)
|
||||
|
||||
a[(x := 12)]
|
||||
a[:(x := 13)]
|
||||
|
||||
# we don't touch expressions in f-strings but if we do one day, don't break 'em
|
||||
f'{(x:=10)}'
|
||||
|
||||
|
||||
def a():
|
||||
return (x := 3)
|
||||
await (b := 1)
|
||||
yield (a := 2)
|
||||
raise (c := 3)
|
||||
|
||||
def this_is_so_dumb() -> (please := no):
|
||||
pass
|
||||
|
||||
async def await_the_walrus():
|
||||
with (x := y):
|
||||
pass
|
||||
|
||||
with (x := y) as z, (a := b) as c:
|
||||
pass
|
||||
|
||||
with (x := await y):
|
||||
pass
|
||||
|
||||
with (x := await a, y := await b):
|
||||
pass
|
||||
|
||||
with ((x := await a, y := await b)):
|
||||
pass
|
||||
|
||||
with (x := await a), (y := await b):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Differences
|
||||
|
||||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -34,7 +34,7 @@
|
||||
lambda: (x := 1)
|
||||
|
||||
a[(x := 12)]
|
||||
-a[:(x := 13)]
|
||||
+a[: (x := 13)]
|
||||
|
||||
# we don't touch expressions in f-strings but if we do one day, don't break 'em
|
||||
f"{(x:=10)}"
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
||||
```py
|
||||
if foo := 0:
|
||||
pass
|
||||
|
||||
if foo := 1:
|
||||
pass
|
||||
|
||||
if y := 5 + 5:
|
||||
pass
|
||||
|
||||
y = (x := 0)
|
||||
|
||||
y += (x := 0)
|
||||
|
||||
(y := 5 + 5)
|
||||
|
||||
test: int = (test2 := 2)
|
||||
|
||||
a, b = (test := (1, 2))
|
||||
|
||||
# see also https://github.com/psf/black/issues/2139
|
||||
assert (foo := 42 - 12)
|
||||
|
||||
foo(x=(y := f(x)))
|
||||
|
||||
|
||||
def foo(answer=(p := 42)):
|
||||
...
|
||||
|
||||
|
||||
def foo2(answer: (p := 42) = 5):
|
||||
...
|
||||
|
||||
|
||||
lambda: (x := 1)
|
||||
|
||||
a[(x := 12)]
|
||||
a[: (x := 13)]
|
||||
|
||||
# we don't touch expressions in f-strings but if we do one day, don't break 'em
|
||||
f"{(x:=10)}"
|
||||
|
||||
|
||||
def a():
|
||||
return (x := 3)
|
||||
await (b := 1)
|
||||
yield (a := 2)
|
||||
raise (c := 3)
|
||||
|
||||
|
||||
def this_is_so_dumb() -> (please := no):
|
||||
pass
|
||||
|
||||
|
||||
async def await_the_walrus():
|
||||
with (x := y):
|
||||
pass
|
||||
|
||||
with (x := y) as z, (a := b) as c:
|
||||
pass
|
||||
|
||||
with (x := await y):
|
||||
pass
|
||||
|
||||
with (x := await a, y := await b):
|
||||
pass
|
||||
|
||||
with (x := await a, y := await b):
|
||||
pass
|
||||
|
||||
with (x := await a), (y := await b):
|
||||
pass
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
||||
```py
|
||||
if foo := 0:
|
||||
pass
|
||||
|
||||
if foo := 1:
|
||||
pass
|
||||
|
||||
if y := 5 + 5:
|
||||
pass
|
||||
|
||||
y = (x := 0)
|
||||
|
||||
y += (x := 0)
|
||||
|
||||
(y := 5 + 5)
|
||||
|
||||
test: int = (test2 := 2)
|
||||
|
||||
a, b = (test := (1, 2))
|
||||
|
||||
# see also https://github.com/psf/black/issues/2139
|
||||
assert (foo := 42 - 12)
|
||||
|
||||
foo(x=(y := f(x)))
|
||||
|
||||
|
||||
def foo(answer=(p := 42)):
|
||||
...
|
||||
|
||||
|
||||
def foo2(answer: (p := 42) = 5):
|
||||
...
|
||||
|
||||
|
||||
lambda: (x := 1)
|
||||
|
||||
a[(x := 12)]
|
||||
a[:(x := 13)]
|
||||
|
||||
# we don't touch expressions in f-strings but if we do one day, don't break 'em
|
||||
f"{(x:=10)}"
|
||||
|
||||
|
||||
def a():
|
||||
return (x := 3)
|
||||
await (b := 1)
|
||||
yield (a := 2)
|
||||
raise (c := 3)
|
||||
|
||||
|
||||
def this_is_so_dumb() -> (please := no):
|
||||
pass
|
||||
|
||||
|
||||
async def await_the_walrus():
|
||||
with (x := y):
|
||||
pass
|
||||
|
||||
with (x := y) as z, (a := b) as c:
|
||||
pass
|
||||
|
||||
with (x := await y):
|
||||
pass
|
||||
|
||||
with (x := await a, y := await b):
|
||||
pass
|
||||
|
||||
with (x := await a, y := await b):
|
||||
pass
|
||||
|
||||
with (x := await a), (y := await b):
|
||||
pass
|
||||
```
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue