mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
293 lines
7.6 KiB
Text
293 lines
7.6 KiB
Text
---
|
|
source: crates/ruff_python_formatter/tests/fixtures.rs
|
|
input_file: crates/ruff_python_formatter/resources/test/fixtures/black/simple_cases/fmtskip8.py
|
|
---
|
|
## Input
|
|
|
|
```py
|
|
# Make sure a leading comment is not removed.
|
|
def some_func( unformatted, args ): # fmt: skip
|
|
print("I am some_func")
|
|
return 0
|
|
# Make sure this comment is not removed.
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
async def some_async_func( unformatted, args): # fmt: skip
|
|
print("I am some_async_func")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
|
def some_method( self, unformatted, args ): # fmt: skip
|
|
print("I am some_method")
|
|
return 0
|
|
|
|
async def some_async_method( self, unformatted, args ): # fmt: skip
|
|
print("I am some_async_method")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
if unformatted_call( args ): # fmt: skip
|
|
print("First branch")
|
|
# Make sure this is not removed.
|
|
elif another_unformatted_call( args ): # fmt: skip
|
|
print("Second branch")
|
|
else : # fmt: skip
|
|
print("Last branch")
|
|
|
|
|
|
while some_condition( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
for i in some_iter( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_for():
|
|
async for i in some_async_iter( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
try : # fmt: skip
|
|
some_call()
|
|
except UnformattedError as ex: # fmt: skip
|
|
handle_exception()
|
|
finally : # fmt: skip
|
|
finally_call()
|
|
|
|
|
|
with give_me_context( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_with():
|
|
async with give_me_async_context( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
```
|
|
|
|
## Black Differences
|
|
|
|
```diff
|
|
--- Black
|
|
+++ Ruff
|
|
@@ -1,62 +1,61 @@
|
|
# Make sure a leading comment is not removed.
|
|
-def some_func( unformatted, args ): # fmt: skip
|
|
+def some_func(unformatted, args): # fmt: skip
|
|
print("I am some_func")
|
|
return 0
|
|
# Make sure this comment is not removed.
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
-async def some_async_func( unformatted, args): # fmt: skip
|
|
+async def some_async_func(unformatted, args): # fmt: skip
|
|
print("I am some_async_func")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
-class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
|
- def some_method( self, unformatted, args ): # fmt: skip
|
|
+class SomeClass(Unformatted, SuperClasses): # fmt: skip
|
|
+ def some_method(self, unformatted, args): # fmt: skip
|
|
print("I am some_method")
|
|
return 0
|
|
|
|
- async def some_async_method( self, unformatted, args ): # fmt: skip
|
|
+ async def some_async_method(self, unformatted, args): # fmt: skip
|
|
print("I am some_async_method")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
-if unformatted_call( args ): # fmt: skip
|
|
+if unformatted_call(args): # fmt: skip
|
|
print("First branch")
|
|
# Make sure this is not removed.
|
|
-elif another_unformatted_call( args ): # fmt: skip
|
|
+elif another_unformatted_call(args): # fmt: skip
|
|
print("Second branch")
|
|
-else : # fmt: skip
|
|
+else: # fmt: skip
|
|
print("Last branch")
|
|
|
|
|
|
-while some_condition( unformatted, args ): # fmt: skip
|
|
+while some_condition(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
-for i in some_iter( unformatted, args ): # fmt: skip
|
|
+for i in some_iter(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_for():
|
|
- async for i in some_async_iter( unformatted, args ): # fmt: skip
|
|
- print("Do something")
|
|
+ NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
|
|
|
|
|
-try : # fmt: skip
|
|
+try:
|
|
+ # fmt: skip
|
|
some_call()
|
|
-except UnformattedError as ex: # fmt: skip
|
|
- handle_exception()
|
|
-finally : # fmt: skip
|
|
+except UnformattedError as ex: # fmt: skip
|
|
+ handle_exception() # fmt: skip
|
|
+finally:
|
|
finally_call()
|
|
|
|
|
|
-with give_me_context( unformatted, args ): # fmt: skip
|
|
+with give_me_context(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_with():
|
|
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
|
- print("Do something")
|
|
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
|
```
|
|
|
|
## Ruff Output
|
|
|
|
```py
|
|
# Make sure a leading comment is not removed.
|
|
def some_func(unformatted, args): # fmt: skip
|
|
print("I am some_func")
|
|
return 0
|
|
# Make sure this comment is not removed.
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
async def some_async_func(unformatted, args): # fmt: skip
|
|
print("I am some_async_func")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
class SomeClass(Unformatted, SuperClasses): # fmt: skip
|
|
def some_method(self, unformatted, args): # fmt: skip
|
|
print("I am some_method")
|
|
return 0
|
|
|
|
async def some_async_method(self, unformatted, args): # fmt: skip
|
|
print("I am some_async_method")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
if unformatted_call(args): # fmt: skip
|
|
print("First branch")
|
|
# Make sure this is not removed.
|
|
elif another_unformatted_call(args): # fmt: skip
|
|
print("Second branch")
|
|
else: # fmt: skip
|
|
print("Last branch")
|
|
|
|
|
|
while some_condition(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
for i in some_iter(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_for():
|
|
NOT_YET_IMPLEMENTED_StmtAsyncFor # fmt: skip
|
|
|
|
|
|
try:
|
|
# fmt: skip
|
|
some_call()
|
|
except UnformattedError as ex: # fmt: skip
|
|
handle_exception() # fmt: skip
|
|
finally:
|
|
finally_call()
|
|
|
|
|
|
with give_me_context(unformatted, args): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_with():
|
|
NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
|
```
|
|
|
|
## Black Output
|
|
|
|
```py
|
|
# Make sure a leading comment is not removed.
|
|
def some_func( unformatted, args ): # fmt: skip
|
|
print("I am some_func")
|
|
return 0
|
|
# Make sure this comment is not removed.
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
async def some_async_func( unformatted, args): # fmt: skip
|
|
print("I am some_async_func")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
class SomeClass( Unformatted, SuperClasses ): # fmt: skip
|
|
def some_method( self, unformatted, args ): # fmt: skip
|
|
print("I am some_method")
|
|
return 0
|
|
|
|
async def some_async_method( self, unformatted, args ): # fmt: skip
|
|
print("I am some_async_method")
|
|
await asyncio.sleep(1)
|
|
|
|
|
|
# Make sure a leading comment is not removed.
|
|
if unformatted_call( args ): # fmt: skip
|
|
print("First branch")
|
|
# Make sure this is not removed.
|
|
elif another_unformatted_call( args ): # fmt: skip
|
|
print("Second branch")
|
|
else : # fmt: skip
|
|
print("Last branch")
|
|
|
|
|
|
while some_condition( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
for i in some_iter( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_for():
|
|
async for i in some_async_iter( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
try : # fmt: skip
|
|
some_call()
|
|
except UnformattedError as ex: # fmt: skip
|
|
handle_exception()
|
|
finally : # fmt: skip
|
|
finally_call()
|
|
|
|
|
|
with give_me_context( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
|
|
|
|
async def test_async_with():
|
|
async with give_me_async_context( unformatted, args ): # fmt: skip
|
|
print("Do something")
|
|
```
|
|
|
|
|