From f58bef46a2b285912abe2f0d35d5da89d96d4cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Sat, 30 Nov 2024 13:50:29 +0200 Subject: [PATCH] Retracted the TaskInfo type annotation changes --- docs/versionhistory.rst | 6 +----- src/anyio/_backends/_asyncio.py | 4 +++- src/anyio/_core/_testing.py | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index e97dff46..ce4c4db0 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -5,11 +5,7 @@ This library adheres to `Semantic Versioning 2.0 `_. **UNRELEASED** -- Improved compatibility with asyncio's eager task factories: - - * Updated the annotation of ``TaskInfo.coro`` to allow it to be ``None`` - * Updated ``TaskGroup`` to work with asyncio eager task factories - +- Updated ``TaskGroup`` to work with asyncio's eager task factories (`#764 `_) - Fixed a misleading ``ValueError`` in the context of DNS failures (`#815 `_; PR by @graingert) diff --git a/src/anyio/_backends/_asyncio.py b/src/anyio/_backends/_asyncio.py index a6bce650..38b68f4d 100644 --- a/src/anyio/_backends/_asyncio.py +++ b/src/anyio/_backends/_asyncio.py @@ -2142,7 +2142,9 @@ def __init__(self, task: asyncio.Task): else: parent_id = task_state.parent_id - super().__init__(id(task), parent_id, task.get_name(), task.get_coro()) + coro = task.get_coro() + assert coro is not None, "created TaskInfo from a completed Task" + super().__init__(id(task), parent_id, task.get_name(), coro) self._task = weakref.ref(task) def has_pending_cancellation(self) -> bool: diff --git a/src/anyio/_core/_testing.py b/src/anyio/_core/_testing.py index 2ab9ea20..9e28b227 100644 --- a/src/anyio/_core/_testing.py +++ b/src/anyio/_core/_testing.py @@ -24,14 +24,14 @@ def __init__( id: int, parent_id: int | None, name: str | None, - coro: Generator[Any, Any, Any] | Awaitable[Any] | None, + coro: Generator[Any, Any, Any] | Awaitable[Any], ): func = get_current_task self._name = f"{func.__module__}.{func.__qualname__}" self.id: int = id self.parent_id: int | None = parent_id self.name: str | None = name - self.coro: Generator[Any, Any, Any] | Awaitable[Any] | None = coro + self.coro: Generator[Any, Any, Any] | Awaitable[Any] = coro def __eq__(self, other: object) -> bool: if isinstance(other, TaskInfo):