Skip to content

Commit e657753

Browse files
committed
run_coroutine_threadsafe type fix
1 parent a410f25 commit e657753

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stdlib/asyncio/tasks.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from _asyncio import (
99
)
1010
from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator
1111
from typing import Any, Literal, Protocol, TypeVar, overload
12+
from types import CoroutineType
1213
from typing_extensions import TypeAlias
1314

1415
from . import _CoroutineLike
@@ -79,7 +80,10 @@ if sys.version_info >= (3, 12):
7980
_FutureLike: TypeAlias = Future[_T] | Awaitable[_T]
8081
else:
8182
_FutureLike: TypeAlias = Future[_T] | Generator[Any, None, _T] | Awaitable[_T]
83+
8284
_TaskYieldType: TypeAlias = Future[object] | None
85+
_ThreadsafeCouroutineType: TypeAlias = Coroutine[Any, Any, _T] | CoroutineType[Any, Any, _T]
86+
8387

8488
FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED
8589
FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION
@@ -347,7 +351,8 @@ else:
347351
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool
348352
) -> Future[list[_T | BaseException]]: ...
349353

350-
def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
354+
# unlike some asyncio apis, This does strict runtime checking of actually being a coroutine, not of any future-like
355+
def run_coroutine_threadsafe(coro: _ThreadsafeCouroutineType[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
351356

352357
if sys.version_info >= (3, 10):
353358
def shield(arg: _FutureLike[_T]) -> Future[_T]: ...

0 commit comments

Comments
 (0)