Skip to content

Commit

Permalink
Merge c9307ee into ce941c5
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jan 20, 2024
2 parents ce941c5 + c9307ee commit a4be4f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
- Fixed passing ``total_tokens`` to ``anyio.CapacityLimiter()`` as a keyword argument
not working on the ``trio`` backend
(`#515 <https://github.com/agronholm/anyio/issues/515>`_)
- Fixed inability to start tasks from ``async_generator_asend`` objects on asyncio

**4.2.0**

Expand Down
6 changes: 2 additions & 4 deletions src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from asyncio.base_events import _run_until_complete_cb # type: ignore[attr-defined]
from collections import OrderedDict, deque
from collections.abc import AsyncIterator, Generator, Iterable
from collections.abc import AsyncIterator, Coroutine, Generator, Iterable
from concurrent.futures import Future
from contextlib import suppress
from contextvars import Context, copy_context
Expand All @@ -28,7 +28,6 @@
CORO_RUNNING,
CORO_SUSPENDED,
getcoroutinestate,
iscoroutine,
)
from io import IOBase
from os import PathLike
Expand All @@ -45,7 +44,6 @@
Callable,
Collection,
ContextManager,
Coroutine,
Mapping,
Optional,
Sequence,
Expand Down Expand Up @@ -741,7 +739,7 @@ def task_done(_task: asyncio.Task) -> None:
parent_id = id(self.cancel_scope._host_task)

coro = func(*args, **kwargs)
if not iscoroutine(coro):
if not isinstance(coro, Coroutine):
prefix = f"{func.__module__}." if hasattr(func, "__module__") else ""
raise TypeError(
f"Expected {prefix}{func.__qualname__}() to return a coroutine, but "
Expand Down
16 changes: 16 additions & 0 deletions tests/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,22 @@ async def wait_cancel() -> None:
await cancelled.wait()


async def test_start_soon_from_asend() -> None:
started = False

async def genfunc() -> AsyncGenerator[None, None]:
nonlocal started
started = True
yield

generator = genfunc()
async with anyio.create_task_group() as task_group:
task_group.start_soon(generator.asend, None)

assert started
await generator.aclose()


class TestTaskStatusTyping:
"""
These tests do not do anything at run time, but since the test suite is also checked
Expand Down

0 comments on commit a4be4f5

Please sign in to comment.