mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-16 01:25:22 +00:00
format StmtAsyncWith (#5376)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
1979103ec0
commit
c7adb9117f
6 changed files with 125 additions and 71 deletions
|
@ -140,17 +140,7 @@ async def wat():
|
|||
|
||||
if inner_imports.are_evil():
|
||||
# Explains why we have this if.
|
||||
@@ -82,8 +82,7 @@
|
||||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
- async with X.open_async() as x: # Some more comments
|
||||
- result = await x.method1()
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
print("A OK", file=sys.stdout)
|
||||
@@ -93,4 +92,4 @@
|
||||
@@ -93,4 +93,4 @@
|
||||
|
||||
# Some closing comments.
|
||||
# Maybe Vim or Emacs directives for formatting.
|
||||
|
@ -246,7 +236,8 @@ class Foo:
|
|||
async def wat():
|
||||
# This comment, for some reason \
|
||||
# contains a trailing backslash.
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith # Some more comments
|
||||
async with X.open_async() as x: # Some more comments
|
||||
result = await x.method1()
|
||||
# Comment after ending a block.
|
||||
if result:
|
||||
print("A OK", file=sys.stdout)
|
||||
|
|
|
@ -221,7 +221,7 @@ d={'a':1,
|
|||
# Comment 1
|
||||
|
||||
# Comment 2
|
||||
@@ -18,30 +16,53 @@
|
||||
@@ -18,30 +16,54 @@
|
||||
|
||||
# fmt: off
|
||||
def func_no_args():
|
||||
|
@ -253,7 +253,8 @@ d={'a':1,
|
|||
- await conn.do_what_i_mean('SELECT bobby, tables FROM xkcd', timeout=2)
|
||||
- await asyncio.sleep(1)
|
||||
+ "Single-line docstring. Multiline is harder to reformat."
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
+ async with some_connection() as conn:
|
||||
+ await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
+ await asyncio.sleep(1)
|
||||
+
|
||||
+
|
||||
|
@ -296,7 +297,7 @@ d={'a':1,
|
|||
|
||||
|
||||
def spaces_types(
|
||||
@@ -51,7 +72,7 @@
|
||||
@@ -51,7 +73,7 @@
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
|
@ -305,7 +306,7 @@ d={'a':1,
|
|||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
@@ -64,55 +85,55 @@
|
||||
@@ -64,55 +86,55 @@
|
||||
|
||||
something = {
|
||||
# fmt: off
|
||||
|
@ -381,7 +382,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
|
||||
|
||||
@@ -133,10 +154,10 @@
|
||||
@@ -133,10 +155,10 @@
|
||||
"""Another known limitation."""
|
||||
# fmt: on
|
||||
# fmt: off
|
||||
|
@ -396,7 +397,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
# fmt: off
|
||||
# ...but comments still get reformatted even though they should not be
|
||||
@@ -151,12 +172,10 @@
|
||||
@@ -151,12 +173,10 @@
|
||||
ast_args.kw_defaults,
|
||||
parameters,
|
||||
implicit_default=True,
|
||||
|
@ -411,7 +412,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
_type_comment_re = re.compile(
|
||||
r"""
|
||||
@@ -179,7 +198,8 @@
|
||||
@@ -179,7 +199,8 @@
|
||||
$
|
||||
""",
|
||||
# fmt: off
|
||||
|
@ -421,7 +422,7 @@ d={'a':1,
|
|||
# fmt: on
|
||||
)
|
||||
|
||||
@@ -217,8 +237,7 @@
|
||||
@@ -217,8 +238,7 @@
|
||||
xxxxxxxxxx_xxxxxxxxxxx_xxxxxxx_xxxxxxxxx=5,
|
||||
)
|
||||
# fmt: off
|
||||
|
@ -472,7 +473,8 @@ def func_no_args():
|
|||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ async def test_async_with():
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,62 +1,61 @@
|
||||
@@ -1,62 +1,62 @@
|
||||
# Make sure a leading comment is not removed.
|
||||
-def some_func( unformatted, args ): # fmt: skip
|
||||
+def some_func(unformatted, args): # fmt: skip
|
||||
|
@ -153,8 +153,8 @@ async def test_async_with():
|
|||
|
||||
async def test_async_with():
|
||||
- async with give_me_async_context( unformatted, args ): # fmt: skip
|
||||
- print("Do something")
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||
+ async with give_me_async_context(unformatted, args): # fmt: skip
|
||||
print("Do something")
|
||||
```
|
||||
|
||||
## Ruff Output
|
||||
|
@ -220,7 +220,8 @@ with give_me_context(unformatted, args): # fmt: skip
|
|||
|
||||
|
||||
async def test_async_with():
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith # fmt: skip
|
||||
async with give_me_async_context(unformatted, args): # fmt: skip
|
||||
print("Do something")
|
||||
```
|
||||
|
||||
## Black Output
|
||||
|
|
|
@ -107,25 +107,25 @@ def __await__(): return (yield)
|
|||
```diff
|
||||
--- Black
|
||||
+++ Ruff
|
||||
@@ -1,20 +1,19 @@
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/usr/bin/env python3
|
||||
-import asyncio
|
||||
-import sys
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-
|
||||
-from third_party import X, Y, Z
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
+NOT_YET_IMPLEMENTED_StmtImport
|
||||
|
||||
-from library import some_connection, some_decorator
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
-f"trigger 3.6 mode"
|
||||
-
|
||||
+NOT_YET_IMPLEMENTED_StmtImportFrom
|
||||
+NOT_YET_IMPLEMENTED_ExprJoinedStr
|
||||
|
||||
|
||||
def func_no_args():
|
||||
a
|
||||
@@ -14,7 +13,7 @@
|
||||
b
|
||||
c
|
||||
if True:
|
||||
|
@ -134,17 +134,7 @@ def __await__(): return (yield)
|
|||
if False:
|
||||
...
|
||||
for i in range(10):
|
||||
@@ -26,8 +25,7 @@
|
||||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
- async with some_connection() as conn:
|
||||
- await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
+ NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
@@ -41,12 +39,22 @@
|
||||
@@ -41,12 +40,22 @@
|
||||
debug: bool = False,
|
||||
**kwargs,
|
||||
) -> str:
|
||||
|
@ -171,7 +161,7 @@ def __await__(): return (yield)
|
|||
|
||||
|
||||
def spaces_types(
|
||||
@@ -56,7 +64,7 @@
|
||||
@@ -56,7 +65,7 @@
|
||||
d: dict = {},
|
||||
e: bool = True,
|
||||
f: int = -1,
|
||||
|
@ -180,7 +170,7 @@ def __await__(): return (yield)
|
|||
h: str = "",
|
||||
i: str = r"",
|
||||
):
|
||||
@@ -64,19 +72,16 @@
|
||||
@@ -64,19 +73,16 @@
|
||||
|
||||
|
||||
def spaces2(result=_core.Value(None)):
|
||||
|
@ -207,7 +197,7 @@ def __await__(): return (yield)
|
|||
|
||||
|
||||
def long_lines():
|
||||
@@ -87,7 +92,7 @@
|
||||
@@ -87,7 +93,7 @@
|
||||
ast_args.kw_defaults,
|
||||
parameters,
|
||||
implicit_default=True,
|
||||
|
@ -216,7 +206,7 @@ def __await__(): return (yield)
|
|||
)
|
||||
typedargslist.extend(
|
||||
gen_annotated_params(
|
||||
@@ -96,7 +101,7 @@
|
||||
@@ -96,7 +102,7 @@
|
||||
parameters,
|
||||
implicit_default=True,
|
||||
# trailing standalone comment
|
||||
|
@ -225,7 +215,7 @@ def __await__(): return (yield)
|
|||
)
|
||||
_type_comment_re = re.compile(
|
||||
r"""
|
||||
@@ -118,7 +123,8 @@
|
||||
@@ -118,7 +124,8 @@
|
||||
)
|
||||
$
|
||||
""",
|
||||
|
@ -235,7 +225,7 @@ def __await__(): return (yield)
|
|||
)
|
||||
|
||||
|
||||
@@ -135,14 +141,8 @@
|
||||
@@ -135,14 +142,8 @@
|
||||
a,
|
||||
**kwargs,
|
||||
) -> A:
|
||||
|
@ -284,7 +274,8 @@ def func_no_args():
|
|||
|
||||
async def coroutine(arg, exec=False):
|
||||
"Single-line docstring. Multiline is harder to reformat."
|
||||
NOT_YET_IMPLEMENTED_StmtAsyncWith
|
||||
async with some_connection() as conn:
|
||||
await conn.do_what_i_mean("SELECT bobby, tables FROM xkcd", timeout=2)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue