@@ -9,6 +9,7 @@ from _asyncio import (
9
9
)
10
10
from collections .abc import AsyncIterator , Awaitable , Coroutine , Generator , Iterable , Iterator
11
11
from typing import Any , Literal , Protocol , TypeVar , overload
12
+ from types import CoroutineType
12
13
from typing_extensions import TypeAlias
13
14
14
15
from . import _CoroutineLike
@@ -79,7 +80,10 @@ if sys.version_info >= (3, 12):
79
80
_FutureLike : TypeAlias = Future [_T ] | Awaitable [_T ]
80
81
else :
81
82
_FutureLike : TypeAlias = Future [_T ] | Generator [Any , None , _T ] | Awaitable [_T ]
83
+
82
84
_TaskYieldType : TypeAlias = Future [object ] | None
85
+ _ThreadsafeCouroutineType : TypeAlias = Coroutine [Any , Any , _T ] | CoroutineType [Any , Any , _T ]
86
+
83
87
84
88
FIRST_COMPLETED = concurrent .futures .FIRST_COMPLETED
85
89
FIRST_EXCEPTION = concurrent .futures .FIRST_EXCEPTION
@@ -347,7 +351,8 @@ else:
347
351
* coros_or_futures : _FutureLike [_T ], loop : AbstractEventLoop | None = None , return_exceptions : bool
348
352
) -> Future [list [_T | BaseException ]]: ...
349
353
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 ]: ...
351
356
352
357
if sys .version_info >= (3 , 10 ):
353
358
def shield (arg : _FutureLike [_T ]) -> Future [_T ]: ...
0 commit comments