Add a trailing newline to all .py.expect files (#3156)

This just re-formats all the `.py.expect` files with Black, both to add a trailing newline and be doubly-certain that they're correctly formatted.

I also ensured that we add a hard line break after each statement, and that we avoid including an extra newline in the generated Markdown (since the code should contain the exact expected newlines).
This commit is contained in:
Charlie Marsh 2023-02-22 21:29:27 -05:00 committed by GitHub
parent c1ddcb8a60
commit 5fd827545b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
104 changed files with 182 additions and 1464 deletions

View file

@ -882,6 +882,8 @@ impl Format<ASTFormatContext<'_>> for FormatStmt<'_> {
}
}?;
write!(f, [hard_line_break()])?;
// Any trailing comments come on the lines after.
for trivia in &self.item.trivia {
if matches!(trivia.relationship, Relationship::Trailing) {

View file

@ -208,7 +208,7 @@ mod tests {
impl std::fmt::Display for CodeFrame<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
writeln!(f, "```{}", self.language)?;
writeln!(f, "{}", self.code)?;
write!(f, "{}", self.code)?;
writeln!(f, "```")?;
writeln!(f)
}

View file

@ -28,7 +28,6 @@ if 10 .real:
y = 100[no]
y = 100(no)
```
## Black Differences
@ -75,10 +74,7 @@ y = 100(no)
y = 100[no]
-y = 100(no)
\ No newline at end of file
+y = 100((no))
\ No newline at end of file
```
## Ruff Output

View file

@ -12,7 +12,6 @@ pem_spam = lambda l, spam = {
"x": 3
}: not spam.get(l.strip())
lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
```
## Black Differences
@ -26,10 +25,7 @@ lambda x=lambda y={1: 3}: y['x':lambda y: {1: 2}]: x
pass
pem_spam = lambda l, spam={"x": 3}: not spam.get(l.strip())
-lambda x=lambda y={1: 3}: y["x" : lambda y: {1: 2}]: x
\ No newline at end of file
+lambda x=lambda y={1: 3}: y['x' : lambda y: {1: 2}]: x
\ No newline at end of file
```
## Ruff Output

View file

@ -1,121 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_blank_parentheses.py
---
## Input
```py
class SimpleClassWithBlankParentheses():
pass
class ClassWithSpaceParentheses ( ):
first_test_data = 90
second_test_data = 100
def test_func(self):
return None
class ClassWithEmptyFunc(object):
def func_with_blank_parentheses():
return 5
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
class InsideFunc():
pass
class NormalClass (
):
def func_for_testing(self, first, second):
sum = first + second
return sum
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -27,4 +27,4 @@
class NormalClass:
def func_for_testing(self, first, second):
sum = first + second
- return sum
\ No newline at end of file
+ return sum
```
## Ruff Output
```py
class SimpleClassWithBlankParentheses:
pass
class ClassWithSpaceParentheses:
first_test_data = 90
second_test_data = 100
def test_func(self):
return None
class ClassWithEmptyFunc(object):
def func_with_blank_parentheses():
return 5
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
class InsideFunc:
pass
class NormalClass:
def func_for_testing(self, first, second):
sum = first + second
return sum
```
## Black Output
```py
class SimpleClassWithBlankParentheses:
pass
class ClassWithSpaceParentheses:
first_test_data = 90
second_test_data = 100
def test_func(self):
return None
class ClassWithEmptyFunc(object):
def func_with_blank_parentheses():
return 5
def public_func_with_blank_parentheses():
return None
def class_under_the_func_with_blank_parentheses():
class InsideFunc:
pass
class NormalClass:
def func_for_testing(self, first, second):
sum = first + second
return sum
```

View file

@ -1,468 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/class_methods_new_line.py
---
## Input
```py
class ClassSimplest:
pass
class ClassWithSingleField:
a = 1
class ClassWithJustTheDocstring:
"""Just a docstring."""
class ClassWithInit:
def __init__(self):
pass
class ClassWithTheDocstringAndInit:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithInitAndVars:
cls_var = 100
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
def __init__(self):
pass
class ClassWithDecoInit:
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVars:
cls_var = 100
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
@deco
def __init__(self):
pass
class ClassSimplestWithInner:
class Inner:
pass
class ClassSimplestWithInnerWithDocstring:
class Inner:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithSingleFieldWithInner:
a = 1
class Inner:
pass
class ClassWithJustTheDocstringWithInner:
"""Just a docstring."""
class Inner:
pass
class ClassWithInitWithInner:
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithDecoInitWithInner:
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
"""Test class"""
class Inner:
pass
cls_var = 100
@deco
def __init__(self):
pass
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -162,4 +162,4 @@
@deco
def __init__(self):
- pass
\ No newline at end of file
+ pass
```
## Ruff Output
```py
class ClassSimplest:
pass
class ClassWithSingleField:
a = 1
class ClassWithJustTheDocstring:
"""Just a docstring."""
class ClassWithInit:
def __init__(self):
pass
class ClassWithTheDocstringAndInit:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithInitAndVars:
cls_var = 100
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
def __init__(self):
pass
class ClassWithDecoInit:
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVars:
cls_var = 100
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
@deco
def __init__(self):
pass
class ClassSimplestWithInner:
class Inner:
pass
class ClassSimplestWithInnerWithDocstring:
class Inner:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithSingleFieldWithInner:
a = 1
class Inner:
pass
class ClassWithJustTheDocstringWithInner:
"""Just a docstring."""
class Inner:
pass
class ClassWithInitWithInner:
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithDecoInitWithInner:
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
"""Test class"""
class Inner:
pass
cls_var = 100
@deco
def __init__(self):
pass
```
## Black Output
```py
class ClassSimplest:
pass
class ClassWithSingleField:
a = 1
class ClassWithJustTheDocstring:
"""Just a docstring."""
class ClassWithInit:
def __init__(self):
pass
class ClassWithTheDocstringAndInit:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithInitAndVars:
cls_var = 100
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
def __init__(self):
pass
class ClassWithDecoInit:
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVars:
cls_var = 100
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstring:
"""Test class"""
cls_var = 100
@deco
def __init__(self):
pass
class ClassSimplestWithInner:
class Inner:
pass
class ClassSimplestWithInnerWithDocstring:
class Inner:
"""Just a docstring."""
def __init__(self):
pass
class ClassWithSingleFieldWithInner:
a = 1
class Inner:
pass
class ClassWithJustTheDocstringWithInner:
"""Just a docstring."""
class Inner:
pass
class ClassWithInitWithInner:
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
def __init__(self):
pass
class ClassWithDecoInitWithInner:
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsWithInner:
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner:
"""Test class"""
cls_var = 100
class Inner:
pass
@deco
def __init__(self):
pass
class ClassWithDecoInitAndVarsAndDocstringWithInner2:
"""Test class"""
class Inner:
pass
cls_var = 100
@deco
def __init__(self):
pass
```

View file

@ -77,7 +77,6 @@ if True:
ec2client.get_waiter("instance_stopped").wait(
InstanceIds=[instance.id], WaiterConfig={"Delay": 5,},
)
```
## Black Differences
@ -107,14 +106,6 @@ if True:
},
)
ec2client.get_waiter("instance_stopped").wait(
@@ -96,4 +96,4 @@
WaiterConfig={
"Delay": 5,
},
- )
\ No newline at end of file
+ )
```
## Ruff Output
@ -219,7 +210,6 @@ if True:
"Delay": 5,
},
)
```
## Black Output

View file

@ -15,7 +15,6 @@ def bobtwo(): \
\
# some comment here
pass
```
## Black Differences
@ -31,12 +30,9 @@ def bobtwo(): \
-def bobtwo(): # some comment here
- pass
\ No newline at end of file
+def bobtwo():
+ # some comment here
+ pass
pass
```
## Ruff Output
@ -50,7 +46,6 @@ def bob():
def bobtwo():
# some comment here
pass
```
## Black Output

View file

@ -171,7 +171,6 @@ instruction()#comment with bad spacing
# END COMMENTS
# MORE END COMMENTS
```
## Black Differences
@ -361,10 +360,7 @@ instruction()#comment with bad spacing
+instruction() #comment with bad spacing
# END COMMENTS
-# MORE END COMMENTS
\ No newline at end of file
+# MORE END COMMENTS
# MORE END COMMENTS
```
## Ruff Output
@ -550,7 +546,6 @@ instruction() #comment with bad spacing
# END COMMENTS
# MORE END COMMENTS
```
## Black Output

View file

@ -100,7 +100,6 @@ def foo3(list_a, list_b):
)
.filter(User.xyz.is_(None))
)
```
## Black Differences
@ -240,12 +239,10 @@ def foo3(list_a, list_b):
- )
- .filter(User.xyz.is_(None))
- )
\ No newline at end of file
+ return # Standlone comment but weirdly placed.
+ User.query.filter(User.foo == "bar").filter(
+ db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
+ ).filter(User.xyz.is_(None))
```
## Ruff Output
@ -345,7 +342,6 @@ def foo3(list_a, list_b):
User.query.filter(User.foo == "bar").filter(
db.or_(User.field_a.astext.in_(list_a), User.field_b.astext.in_(list_b))
).filter(User.xyz.is_(None))
```
## Black Output

View file

@ -124,7 +124,6 @@ call_to_some_function_asdf(
)
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
```
## Black Differences
@ -289,8 +288,6 @@ aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*ite
)
aaaaaaaaaaaaa, bbbbbbbbb = map(list, map(itertools.chain.from_iterable, zip(*items))) # type: ignore[arg-type]
\ No newline at end of file
```
## Ruff Output

View file

@ -145,7 +145,6 @@ def foo():
# A standalone comment
def bar():
pass
```
## Black Differences
@ -280,11 +279,8 @@ def bar():
@decorator1
-# A standalone comment
def bar():
- pass
\ No newline at end of file
+ # A standalone comment
+ pass
pass
```
## Ruff Output
@ -457,7 +453,6 @@ def foo():
def bar():
# A standalone comment
pass
```
## Black Output

View file

@ -187,7 +187,6 @@ class C:
key9: value9
}
)
```
## Black Differences
@ -473,14 +472,6 @@ class C:
assert (
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
@@ -178,4 +201,4 @@
key8: value8,
key9: value9,
}
- )
\ No newline at end of file
+ )
```
## Ruff Output
@ -690,7 +681,6 @@ class C:
key9: value9,
}
)
```
## Black Output

View file

@ -187,7 +187,6 @@ class C:
key9: value9,
}
)
```
## Black Differences
@ -473,14 +472,6 @@ class C:
assert (
expectedexpectedexpectedexpectedexpectedexpectedexpectedexpectedexpect
@@ -178,4 +201,4 @@
key8: value8,
key9: value9,
}
- )
\ No newline at end of file
+ )
```
## Ruff Output
@ -690,7 +681,6 @@ class C:
key9: value9,
}
)
```
## Black Output

View file

@ -1,50 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/docstring_no_extra_empty_line_before_eof.py
---
## Input
```py
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
"""A docstring."""
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -1,4 +1,4 @@
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
- """A docstring."""
\ No newline at end of file
+ """A docstring."""
```
## Ruff Output
```py
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
"""A docstring."""
```
## Black Output
```py
# Make sure when the file ends with class's docstring,
# It doesn't add extra blank lines.
class ClassWithDocstring:
"""A docstring."""
```

View file

@ -98,7 +98,6 @@ def g():
syms.argument,
}:
return NO
```
## Black Differences
@ -119,7 +118,7 @@ def g():
t = leaf.type
p = leaf.parent # trailing comment
@@ -25,23 +25,30 @@
@@ -25,35 +25,41 @@
return NO
if prevp.type == token.EQUAL:
@ -165,11 +164,11 @@ def g():
return NO
@@ -49,11 +56,10 @@
###############################################################################
# SECTION BECAUSE SECTIONS
###############################################################################
-
def g():
- NO = ""
- SPACE = " "
@ -200,8 +199,6 @@ def g():
- syms.arglist,
- syms.argument,
- }:
- return NO
\ No newline at end of file
+ if (
+ prevp.parent
+ and prevp.parent.type
@ -213,8 +210,7 @@ def g():
+ syms.argument,
+ }
+ ):
+ return NO
return NO
```
## Ruff Output
@ -319,7 +315,6 @@ def g():
}
):
return NO
```
## Black Output

View file

@ -260,7 +260,6 @@ bbbb >> bbbb * bbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ^bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa^aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
last_call()
# standalone comment at ENDMARKER
```
## Black Differences
@ -308,7 +307,7 @@ last_call()
()
(1,)
(1, 2)
@@ -88,33 +90,34 @@
@@ -88,32 +90,33 @@
]
{i for i in (1, 2, 3)}
{(i**2) for i in (1, 2, 3)}
@ -346,12 +345,10 @@ last_call()
arg,
another,
- kwarg="hey",
- **kwargs
+ kwarg='hey',
+ **kwargs,
**kwargs,
) # note: no trailing comma pre-3.6
call(*gidgets[:2])
call(a, *gidgets[:2])
@@ -122,8 +125,8 @@
call(b, **self.screen_kwargs)
lukasz.langa.pl
@ -370,19 +367,19 @@ last_call()
-xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
+xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = (
+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
+)
+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = (
+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
)
-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod( # type: ignore
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = (
+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__))
+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)) # type: ignore
)
-xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = classmethod(
- sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__)
-) # type: ignore
+xxxx_xxx_xxxx_xxxxx_xxxx_xxx: Callable[..., List[SomeClass]] = (
+ classmethod(sync(async_xxxx_xxx_xxxx_xxxxx_xxxx_xxx.__func__))
+)
slice[0]
slice[0:1]
slice[0:1:2]
@ -436,10 +433,18 @@ last_call()
g = 1, *"ten"
-what_is_up_with_those_new_coord_names = (coord_names + set(vars_to_create)) + set(
- vars_to_remove
-)
+what_is_up_with_those_new_coord_names = (
+ (coord_names
+ + set(vars_to_create))
+ + set(vars_to_remove)
)
-what_is_up_with_those_new_coord_names = (coord_names | set(vars_to_create)) - set(
- vars_to_remove
-)
+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(
@ -447,11 +452,7 @@ last_call()
- )
- .order_by(models.Customer.id.asc())
- .all()
+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(
@ -461,11 +462,7 @@ last_call()
- models.Customer.id.asc(),
- )
- .all()
+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(
+ models.Customer.account_id == account_id,
+ models.Customer.email == email_address,
@ -533,15 +530,6 @@ last_call()
^ aaaaaaaaaaaaaaaa.i
<< aaaaaaaaaaaaaaaa.k
>> aaaaaaaaaaaaaaaa.l**aaaaaaaaaaaaaaaa.m // aaaaaaaaaaaaaaaa.n
@@ -366,5 +371,4 @@
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
-last_call()
-# standalone comment at ENDMARKER
\ No newline at end of file
+last_call()# standalone comment at ENDMARKER
```
## Ruff Output
@ -920,8 +908,8 @@ bbbb >> bbbb * bbbb
^ bbbb.a & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
^ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
last_call()# standalone comment at ENDMARKER
last_call()
# standalone comment at ENDMARKER
```
## Black Output
@ -1043,7 +1031,7 @@ call(
arg,
another,
kwarg="hey",
**kwargs
**kwargs,
) # note: no trailing comma pre-3.6
call(*gidgets[:2])
call(a, *gidgets[:2])

View file

@ -46,7 +46,6 @@ def test_calculate_fades():
]
# fmt: on
```
## Black Differences
@ -63,9 +62,9 @@ def test_calculate_fades():
# Test data:
# Position, Volume, State, TmSt/TmEx/None, [call, [arg1...]]
-
-@pytest.mark.parametrize('test', [
-@pytest.mark.parametrize('test', [
-
- # Test don't manage the volume
+@pytest.mark.parametrize(
+ 'test',
@ -106,10 +105,7 @@ def test_calculate_fades():
+ (None, 4, 0, 0, 10, 0, 0, 6, 10),
]
-# fmt: on
\ No newline at end of file
+# fmt: on
# fmt: on
```
## Ruff Output
@ -159,7 +155,6 @@ def test_calculate_fades():
]
# fmt: on
```
## Black Output

View file

@ -23,7 +23,6 @@ x = [
x = [
1, 2, 3, 4
]
```
## Black Differences
@ -54,7 +53,6 @@ x = [
]
# fmt: on
```
## Ruff Output

View file

@ -19,7 +19,6 @@ def f(): pass
3, 4,
])
def f(): pass
```
## Black Differences
@ -47,14 +46,6 @@ def f(): pass
pass
@@ -17,4 +21,4 @@
]
)
def f():
- pass
\ No newline at end of file
+ pass
```
## Ruff Output
@ -84,7 +75,6 @@ def f():
)
def f():
pass
```
## Black Output

View file

@ -90,7 +90,6 @@ if x:
elif unformatted:
# fmt: on
will_be_formatted ()
```
## Black Differences
@ -188,10 +187,7 @@ elif unformatted:
-elif unformatted:
+elif unformatted:
# fmt: on
- will_be_formatted()
\ No newline at end of file
+ will_be_formatted()
will_be_formatted()
```
## Ruff Output
@ -280,7 +276,6 @@ if x:
elif unformatted:
# fmt: on
will_be_formatted()
```
## Black Output

View file

@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
l1 = ["This list should be broken up", "into multiple lines", "because it is way too long"]
l2 = ["But this list shouldn't", "even though it also has", "way too many characters in it"] # fmt: skip
l3 = ["I have", "trailing comma", "so I should be braked",]
```
## Black Differences
@ -30,7 +29,6 @@ l3 = ["I have", "trailing comma", "so I should be braked",]
l3 = [
"I have",
"trailing comma",
```
## Ruff Output

View file

@ -13,7 +13,6 @@ d = 6 # fmt: skip
e = 5
# fmt: on
f = ["This is a very long line that should be formatted into a clearer line ", "by rearranging."]
```
## Black Differences
@ -31,7 +30,6 @@ f = ["This is a very long line that should be formatted into a clearer line ", "
e = 5
# fmt: on
f = [
```
## Ruff Output

View file

@ -15,7 +15,6 @@ if (
print("I'm good!")
else:
print("I'm bad")
```
## Black Differences
@ -33,10 +32,7 @@ else:
+if a == 3 and b != 9 and c is not None: # fmt: skip
print("I'm good!")
else:
- print("I'm bad")
\ No newline at end of file
+ print("I'm bad")
print("I'm bad")
```
## Ruff Output
@ -47,7 +43,6 @@ if a == 3 and b != 9 and c is not None: # fmt: skip
print("I'm good!")
else:
print("I'm bad")
```
## Black Output

View file

@ -11,7 +11,6 @@ class A:
for line in range(10):
if True:
pass # fmt: skip
```
## Black Differences
@ -24,9 +23,7 @@ class A:
for line in range(10):
if True:
- pass # fmt: skip
\ No newline at end of file
+ pass
```
## Ruff Output
@ -37,7 +34,6 @@ class A:
for line in range(10):
if True:
pass
```
## Black Output

View file

@ -10,7 +10,6 @@ a = "this is some code"
b = 5 #fmt:skip
c = 9 #fmt: skip
d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip
```
## Black Differences
@ -23,12 +22,9 @@ d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasu
-b = 5 # fmt:skip
-c = 9 # fmt: skip
-d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" # fmt:skip
\ No newline at end of file
+b = 5 #fmt:skip
+c = 9 #fmt: skip
+d = "thisisasuperlongstringthisisasuperlongstringthisisasuperlongstringthisisasuperlongstring" #fmt:skip
\ No newline at end of file
```
## Ruff Output

View file

@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
a, b = 1, 2
c = 6 # fmt: skip
d = 5
```
## Black Differences
@ -22,8 +21,6 @@ d = 5
-c = 6 # fmt: skip
+c = 6 # fmt: skip
d = 5
\ No newline at end of file
```
## Ruff Output

View file

@ -15,7 +15,6 @@ f"{f'''{'nested'} inner'''} outer"
f"\"{f'{nested} inner'}\" outer"
f"space between opening braces: { {a for a in (1, 2, 3)}}"
f'Hello \'{tricky + "example"}\''
```
## Black Differences
@ -31,7 +30,6 @@ f'Hello \'{tricky + "example"}\''
f"some f-string with {a} {few():.2f} {formatted.values!r}"
f'some f-string with {a} {few(""):.2f} {formatted.values!r}'
f"{f'''{'nested'} inner'''} outer"
```
## Ruff Output

View file

@ -1,223 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/function2.py
---
## Input
```py
def f(
a,
**kwargs,
) -> A:
with cache_dir():
if something:
result = (
CliRunner().invoke(black.main, [str(src1), str(src2), "--diff", "--check"])
)
limited.append(-limited.pop()) # negate top
return A(
very_long_argument_name1=very_long_value_for_the_argument,
very_long_argument_name2=-very.long.value.for_the_argument,
**kwargs,
)
def g():
"Docstring."
def inner():
pass
print("Inner defs should breathe a little.")
def h():
def inner():
pass
print("Inner defs should breathe a little.")
if os.name == "posix":
import termios
def i_should_be_followed_by_only_one_newline():
pass
elif os.name == "nt":
try:
import msvcrt
def i_should_be_followed_by_only_one_newline():
pass
except ImportError:
def i_should_be_followed_by_only_one_newline():
pass
elif False:
class IHopeYouAreHavingALovelyDay:
def __call__(self):
print("i_should_be_followed_by_only_one_newline")
else:
def foo():
pass
with hmm_but_this_should_get_two_preceding_newlines():
pass
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -63,4 +63,4 @@
with hmm_but_this_should_get_two_preceding_newlines():
- pass
\ No newline at end of file
+ pass
```
## Ruff Output
```py
def f(
a,
**kwargs,
) -> A:
with cache_dir():
if something:
result = CliRunner().invoke(
black.main,
[str(src1), str(src2), "--diff", "--check"],
)
limited.append(-limited.pop()) # negate top
return A(
very_long_argument_name1=very_long_value_for_the_argument,
very_long_argument_name2=-very.long.value.for_the_argument,
**kwargs,
)
def g():
"Docstring."
def inner():
pass
print("Inner defs should breathe a little.")
def h():
def inner():
pass
print("Inner defs should breathe a little.")
if os.name == "posix":
import termios
def i_should_be_followed_by_only_one_newline():
pass
elif os.name == "nt":
try:
import msvcrt
def i_should_be_followed_by_only_one_newline():
pass
except ImportError:
def i_should_be_followed_by_only_one_newline():
pass
elif False:
class IHopeYouAreHavingALovelyDay:
def __call__(self):
print("i_should_be_followed_by_only_one_newline")
else:
def foo():
pass
with hmm_but_this_should_get_two_preceding_newlines():
pass
```
## Black Output
```py
def f(
a,
**kwargs,
) -> A:
with cache_dir():
if something:
result = CliRunner().invoke(
black.main,
[str(src1), str(src2), "--diff", "--check"],
)
limited.append(-limited.pop()) # negate top
return A(
very_long_argument_name1=very_long_value_for_the_argument,
very_long_argument_name2=-very.long.value.for_the_argument,
**kwargs,
)
def g():
"Docstring."
def inner():
pass
print("Inner defs should breathe a little.")
def h():
def inner():
pass
print("Inner defs should breathe a little.")
if os.name == "posix":
import termios
def i_should_be_followed_by_only_one_newline():
pass
elif os.name == "nt":
try:
import msvcrt
def i_should_be_followed_by_only_one_newline():
pass
except ImportError:
def i_should_be_followed_by_only_one_newline():
pass
elif False:
class IHopeYouAreHavingALovelyDay:
def __call__(self):
print("i_should_be_followed_by_only_one_newline")
else:
def foo():
pass
with hmm_but_this_should_get_two_preceding_newlines():
pass
```

View file

@ -101,7 +101,6 @@ def f(
)
)
def __await__(): return (yield)
```
## Black Differences
@ -184,9 +183,7 @@ def __await__(): return (yield)
def __await__():
- return (yield)
\ No newline at end of file
+ return yield
```
## Ruff Output
@ -334,7 +331,6 @@ def f(
def __await__():
return yield
```
## Black Output

View file

@ -67,7 +67,6 @@ some_module.some_function(
some_module.some_function(
argument1, (one, two,), argument4, argument5, argument6
)
```
## Black Differences
@ -176,7 +175,6 @@ some_module.some_function(
)
# Inner trailing comma causes outer to explode
```
## Ruff Output

View file

@ -87,7 +87,6 @@ async def main():
async def main():
await (yield)
```
## Black Differences
@ -183,7 +182,7 @@ async def main():
# Keep brackets around non power operations and nested awaits
@@ -82,12 +86,12 @@
@@ -82,11 +86,11 @@
async def main():
@ -197,10 +196,6 @@ async def main():
async def main():
- await (yield)
\ No newline at end of file
+ await (yield)
```
## Ruff Output
@ -303,7 +298,6 @@ async def main():
async def main():
await (yield)
```
## Black Output

View file

@ -41,7 +41,6 @@ try:
a.something
except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error, some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error) as err:
raise err
```
## Black Differences
@ -69,14 +68,6 @@ except (some.really.really.really.looooooooooooooooooooooooooooooooong.module.ov
raise err
try:
@@ -39,4 +37,4 @@
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
) as err:
- raise err
\ No newline at end of file
+ raise err
```
## Ruff Output
@ -122,7 +113,6 @@ except (
some.really.really.really.looooooooooooooooooooooooooooooooong.module.over89.chars.Error,
) as err:
raise err
```
## Black Output

View file

@ -25,7 +25,6 @@ for (k, v) in dfkasdjfldsjflkdsjflkdsjfdslkfjldsjfgkjdshgkljjdsfldgkhsdofudsfuds
# Test deeply nested brackets
for (((((k, v))))) in d.items():
print(k, v)
```
## Black Differences
@ -42,7 +41,7 @@ for (((((k, v))))) in d.items():
if hasattr(module, "_verify_python3_env"):
module._verify_python3_env = lambda: None
@@ -17,11 +17,9 @@
@@ -17,9 +17,7 @@
for (
k,
v,
@ -53,11 +52,6 @@ for (((((k, v))))) in d.items():
print(k, v)
# Test deeply nested brackets
for k, v in d.items():
- print(k, v)
\ No newline at end of file
+ print(k, v)
```
## Ruff Output
@ -88,7 +82,6 @@ for (
# Test deeply nested brackets
for k, v in d.items():
print(k, v)
```
## Black Output

View file

@ -1,302 +0,0 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/remove_newline_after_code_block_open.py
---
## Input
```py
import random
def foo1():
print("The newline above me should be deleted!")
def foo2():
print("All the newlines above me should be deleted!")
def foo3():
print("No newline above me!")
print("There is a newline above me, and that's OK!")
def foo4():
# There is a comment here
print("The newline above me should not be deleted!")
class Foo:
def bar(self):
print("The newline above me should be deleted!")
for i in range(5):
print(f"{i}) The line above me should be removed!")
for i in range(5):
print(f"{i}) The lines above me should be removed!")
for i in range(5):
for j in range(7):
print(f"{i}) The lines above me should be removed!")
if random.randint(0, 3) == 0:
print("The new line above me is about to be removed!")
if random.randint(0, 3) == 0:
print("The new lines above me is about to be removed!")
if random.randint(0, 3) == 0:
if random.uniform(0, 1) > 0.5:
print("Two lines above me are about to be removed!")
while True:
print("The newline above me should be deleted!")
while True:
print("The newlines above me should be deleted!")
while True:
while False:
print("The newlines above me should be deleted!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new line above me is about to be removed!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new lines above me is about to be removed!")
with open("/path/to/file.txt", mode="r") as read_file:
with open("/path/to/output_file.txt", mode="w") as write_file:
write_file.writelines(read_file.readlines())
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -75,4 +75,4 @@
with open("/path/to/file.txt", mode="r") as read_file:
with open("/path/to/output_file.txt", mode="w") as write_file:
- write_file.writelines(read_file.readlines())
\ No newline at end of file
+ write_file.writelines(read_file.readlines())
```
## Ruff Output
```py
import random
def foo1():
print("The newline above me should be deleted!")
def foo2():
print("All the newlines above me should be deleted!")
def foo3():
print("No newline above me!")
print("There is a newline above me, and that's OK!")
def foo4():
# There is a comment here
print("The newline above me should not be deleted!")
class Foo:
def bar(self):
print("The newline above me should be deleted!")
for i in range(5):
print(f"{i}) The line above me should be removed!")
for i in range(5):
print(f"{i}) The lines above me should be removed!")
for i in range(5):
for j in range(7):
print(f"{i}) The lines above me should be removed!")
if random.randint(0, 3) == 0:
print("The new line above me is about to be removed!")
if random.randint(0, 3) == 0:
print("The new lines above me is about to be removed!")
if random.randint(0, 3) == 0:
if random.uniform(0, 1) > 0.5:
print("Two lines above me are about to be removed!")
while True:
print("The newline above me should be deleted!")
while True:
print("The newlines above me should be deleted!")
while True:
while False:
print("The newlines above me should be deleted!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new line above me is about to be removed!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new lines above me is about to be removed!")
with open("/path/to/file.txt", mode="r") as read_file:
with open("/path/to/output_file.txt", mode="w") as write_file:
write_file.writelines(read_file.readlines())
```
## Black Output
```py
import random
def foo1():
print("The newline above me should be deleted!")
def foo2():
print("All the newlines above me should be deleted!")
def foo3():
print("No newline above me!")
print("There is a newline above me, and that's OK!")
def foo4():
# There is a comment here
print("The newline above me should not be deleted!")
class Foo:
def bar(self):
print("The newline above me should be deleted!")
for i in range(5):
print(f"{i}) The line above me should be removed!")
for i in range(5):
print(f"{i}) The lines above me should be removed!")
for i in range(5):
for j in range(7):
print(f"{i}) The lines above me should be removed!")
if random.randint(0, 3) == 0:
print("The new line above me is about to be removed!")
if random.randint(0, 3) == 0:
print("The new lines above me is about to be removed!")
if random.randint(0, 3) == 0:
if random.uniform(0, 1) > 0.5:
print("Two lines above me are about to be removed!")
while True:
print("The newline above me should be deleted!")
while True:
print("The newlines above me should be deleted!")
while True:
while False:
print("The newlines above me should be deleted!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new line above me is about to be removed!")
with open("/path/to/file.txt", mode="w") as file:
file.write("The new lines above me is about to be removed!")
with open("/path/to/file.txt", mode="r") as read_file:
with open("/path/to/output_file.txt", mode="w") as write_file:
write_file.writelines(read_file.readlines())
```

View file

@ -61,7 +61,6 @@ def example7():
def example8():
return (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((None)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
```
## Black Differences
@ -108,14 +107,6 @@ def example8():
def example4():
@@ -82,4 +74,4 @@
def example8():
- return None
\ No newline at end of file
+ return None
```
## Ruff Output
@ -198,7 +189,6 @@ def example7():
def example8():
return None
```
## Black Output

View file

@ -94,7 +94,6 @@ def foo() -> tuple[loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
# Magic trailing comma example
def foo() -> tuple[int, int, int,]:
return 2
```
## Black Differences
@ -237,15 +236,12 @@ def foo() -> tuple[int, int, int,]:
- int,
- ]
-):
- return 2
\ No newline at end of file
+def foo() -> tuple[
+ int,
+ int,
+ int,
+]:
+ return 2
return 2
```
## Ruff Output
@ -366,7 +362,6 @@ def foo() -> tuple[
int,
]:
return 2
```
## Black Output

View file

@ -53,7 +53,6 @@ func(
argument5,
argument6,
)
```
## Black Differences
@ -123,7 +122,6 @@ func(
+) = func1(arg1) and func2(arg2)
-func(argument1, (one, two), argument4, argument5, argument6)
\ No newline at end of file
+func(
+ argument1,
+ (
@ -134,8 +132,6 @@ func(
+ argument5,
+ argument6,
+)
\ No newline at end of file
```
## Ruff Output

View file

@ -26,7 +26,6 @@ def docstring_multiline():
R"""
clear out all of the issues opened in that time :p
"""
```
## Black Differences
@ -53,14 +52,6 @@ def docstring_multiline():
def docstring_singleline():
@@ -17,4 +17,4 @@
def docstring_multiline():
R"""
clear out all of the issues opened in that time :p
- """
\ No newline at end of file
+ """
```
## Ruff Output
@ -86,7 +77,6 @@ def docstring_multiline():
R"""
clear out all of the issues opened in that time :p
"""
```
## Black Output

View file

@ -35,7 +35,6 @@ assert (
a_function(very_long_arguments_that_surpass_the_limit, which_is_eighty_eight_in_this_case_plus_a_bit_more)
== {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
)
```
## Black Differences
@ -115,7 +114,6 @@ assert (
- very_long_arguments_that_surpass_the_limit,
- which_is_eighty_eight_in_this_case_plus_a_bit_more,
-) == {"x": "this need to pass the line limit as well", "b": "but only by a little bit"}
\ No newline at end of file
+assert (
+ a_function(
+ very_long_arguments_that_surpass_the_limit,
@ -126,8 +124,6 @@ assert (
+ "b": "but only by a little bit",
+ }
+)
\ No newline at end of file
```
## Ruff Output

View file

@ -31,7 +31,6 @@ class A:
3,
) < self.connection.mysql_version < (10, 5, 2):
pass
```
## Black Differences
@ -76,8 +75,6 @@ class A:
- 4,
- 3,
- ) < self.connection.mysql_version < (10, 5, 2):
- pass
\ No newline at end of file
+ if (
+ self.connection.mysql_is_mariadb
+ and (
@ -88,8 +85,7 @@ class A:
+ < self.connection.mysql_version
+ < (10, 5, 2)
+ ):
+ pass
pass
```
## Ruff Output
@ -134,7 +130,6 @@ class A:
< (10, 5, 2)
):
pass
```
## Black Output

View file

@ -9,7 +9,6 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_ca
if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
(8, 5, 8) <= get_tk_patchlevel() < (8, 6)):
pass
```
## Black Differences
@ -23,14 +22,11 @@ if (e123456.get_tk_patchlevel() >= (8, 6, 0, 'final') or
- 5,
- 8,
-) <= get_tk_patchlevel() < (8, 6):
- pass
\ No newline at end of file
+if (
+ e123456.get_tk_patchlevel() >= (8, 6, 0, 'final')
+ or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)
+):
+ pass
pass
```
## Ruff Output
@ -41,7 +37,6 @@ if (
or (8, 5, 8) <= get_tk_patchlevel() < (8, 6)
):
pass
```
## Black Output

View file

@ -14,7 +14,6 @@ if True:
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
) % {"reported_username": reported_username, "report_reason": report_reason}
```
## Black Differences
@ -27,10 +26,8 @@ if True:
+ "qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwegqweasdzxcqweasdzxc.",
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
- ) % {"reported_username": reported_username, "report_reason": report_reason}
\ No newline at end of file
+ )
+ % {"reported_username": reported_username, "report_reason": report_reason}
```
## Ruff Output
@ -45,7 +42,6 @@ if True:
"qweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqweasdzxcqwe",
)
% {"reported_username": reported_username, "report_reason": report_reason}
```
## Black Output

View file

@ -39,7 +39,6 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
).xxxxxxxxxxxxxxxxxx(), (
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
```
## Black Differences
@ -68,8 +67,6 @@ assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(
+assert xxxxxxxxx.xxxxxxxxx.xxxxxxxxx(xxxxxxxxx).xxxxxxxxxxxxxxxxxx(), (
"xxx {xxxxxxxxx} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
\ No newline at end of file
```
## Ruff Output

View file

@ -0,0 +1,76 @@
---
source: crates/ruff_python_formatter/src/lib.rs
expression: snapshot
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/tupleassign.py
---
## Input
```py
# This is a standalone comment.
sdfjklsdfsjldkflkjsf, sdfjsdfjlksdljkfsdlkf, sdfsdjfklsdfjlksdljkf, sdsfsdfjskdflsfsdf = 1, 2, 3
# This is as well.
this_will_be_wrapped_in_parens, = struct.unpack(b"12345678901234567890")
(a,) = call()
```
## Black Differences
```diff
--- Black
+++ Ruff
@@ -4,11 +4,7 @@
sdfjsdfjlksdljkfsdlkf,
sdfsdjfklsdfjlksdljkf,
sdsfsdfjskdflsfsdf,
-) = (
- 1,
- 2,
- 3,
-)
+) = 1, 2, 3
# This is as well.
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
```
## Ruff Output
```py
# This is a standalone comment.
(
sdfjklsdfsjldkflkjsf,
sdfjsdfjlksdljkfsdlkf,
sdfsdjfklsdfjlksdljkf,
sdsfsdfjskdflsfsdf,
) = 1, 2, 3
# This is as well.
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
(a,) = call()
```
## Black Output
```py
# This is a standalone comment.
(
sdfjklsdfsjldkflkjsf,
sdfjsdfjlksdljkfsdlkf,
sdfsdjfklsdfjlksdljkf,
sdsfsdfjskdflsfsdf,
) = (
1,
2,
3,
)
# This is as well.
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
(a,) = call()
```