mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00

<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Treat async generators as "await" in ASYNC100. Fixes #13637 ## Test Plan Updated snapshot
119 lines
2.1 KiB
Python
119 lines
2.1 KiB
Python
import anyio
|
|
import asyncio
|
|
import trio
|
|
from contextlib import nullcontext
|
|
|
|
|
|
async def func():
|
|
with trio.fail_after():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with trio.fail_at():
|
|
await ...
|
|
|
|
|
|
async def func():
|
|
with trio.move_on_after():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with trio.move_at():
|
|
await ...
|
|
|
|
|
|
async def func():
|
|
with trio.move_at():
|
|
async with trio.open_nursery():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with trio.move_at():
|
|
async for x in ...:
|
|
...
|
|
|
|
|
|
async def main():
|
|
async with asyncio.timeout(7):
|
|
print({i async for i in long_running_range()})
|
|
|
|
|
|
async def func():
|
|
with anyio.move_on_after(delay=0.2):
|
|
...
|
|
|
|
|
|
async def func():
|
|
with anyio.fail_after():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with anyio.CancelScope():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with anyio.CancelScope(), nullcontext():
|
|
...
|
|
|
|
|
|
async def func():
|
|
with nullcontext(), anyio.CancelScope():
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout(delay=0.2):
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout_at(when=0.2):
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout(delay=0.2), asyncio.TaskGroup():
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout(delay=0.2), asyncio.TaskGroup(), asyncio.timeout(delay=0.2):
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout(delay=0.2), asyncio.TaskGroup(), asyncio.timeout(delay=0.2), asyncio.TaskGroup():
|
|
...
|
|
|
|
|
|
async def func():
|
|
async with asyncio.timeout(delay=0.2), asyncio.timeout(delay=0.2):
|
|
...
|
|
|
|
|
|
# Don't trigger for blocks with a yield statement
|
|
async def foo():
|
|
with trio.fail_after(1):
|
|
yield
|
|
|
|
|
|
async def foo(): # even if only one branch contains a yield, we skip the lint
|
|
with trio.fail_after(1):
|
|
if something:
|
|
...
|
|
else:
|
|
yield
|
|
|
|
|
|
# https://github.com/astral-sh/ruff/issues/12873
|
|
@asynccontextmanager
|
|
async def good_code():
|
|
with anyio.fail_after(10):
|
|
# There's no await keyword here, but we presume that there
|
|
# will be in the caller we yield to, so this is safe.
|
|
yield
|