diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index cad7dde40b01..70247dfecf41 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -1,5 +1,6 @@ import ssl import sys +from _asyncio import _TaskCompatibleCoro from _typeshed import FileDescriptorLike, ReadableBuffer, WriteableBuffer from asyncio import _AwaitableLike, _CoroutineLike from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle, _TaskFactory @@ -83,7 +84,16 @@ class BaseEventLoop(AbstractEventLoop): # Future methods def create_future(self) -> Future[Any]: ... # Tasks methods - if sys.version_info >= (3, 11): + if sys.version_info >= (3, 13): # all Task kwargs added in 3.13.2 + def create_task( + self, + coro: _TaskCompatibleCoro[_T], + *, + name: str | None = None, + context: Context | None = None, + eager_start: bool | None = None, + ) -> Task[_T]: ... + elif sys.version_info >= (3, 11): def create_task(self, coro: _CoroutineLike[_T], *, name: object = None, context: Context | None = None) -> Task[_T]: ... else: def create_task(self, coro: _CoroutineLike[_T], *, name: object = None) -> Task[_T]: ... diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index afe912d01fe1..cd49eab96d1a 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -3,6 +3,7 @@ import sys from _asyncio import ( _get_running_loop as _get_running_loop, _set_running_loop as _set_running_loop, + _TaskCompatibleCoro, get_event_loop as get_event_loop, get_running_loop as get_running_loop, ) @@ -67,8 +68,22 @@ _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object] _ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] _SSLContext: TypeAlias = bool | None | ssl.SSLContext -class _TaskFactory(Protocol): - def __call__(self, loop: AbstractEventLoop, factory: _CoroutineLike[_T], /) -> Future[_T]: ... +if sys.version_info >= (3, 13): # all Task kwargs added in 3.13.2 + class _TaskFactory(Protocol): + def __call__( + self, + loop: AbstractEventLoop, + coro: _TaskCompatibleCoro[_T], + /, + *, + name: str | None = ..., + context: Context | None = None, + eager_start: bool = False, + ) -> Task[_T]: ... + +else: + class _TaskFactory(Protocol): + def __call__(self, loop: AbstractEventLoop, coro: _CoroutineLike[_T], /) -> Task[_T]: ... class Handle: _cancelled: bool @@ -157,7 +172,17 @@ class AbstractEventLoop: @abstractmethod def create_future(self) -> Future[Any]: ... # Tasks methods - if sys.version_info >= (3, 11): + if sys.version_info >= (3, 13): # all Task kwargs added in 3.13.2 + @abstractmethod + def create_task( + self, + coro: _TaskCompatibleCoro[_T], + *, + name: str | None = None, + context: Context | None = None, + eager_start: bool | None = None, + ) -> Task[_T]: ... + elif sys.version_info >= (3, 11): @abstractmethod def create_task( self, coro: _CoroutineLike[_T], *, name: str | None = None, context: Context | None = None