From 7bdf4655e0514cb3f1b462e1181d0b16cbc68125 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 20 Jul 2018 17:10:52 +0200 Subject: [PATCH] Add missing asyncio 3.7 top-level functions (#2320) --- stdlib/3/asyncio/__init__.pyi | 14 ++++++++++++++ stdlib/3/asyncio/events.pyi | 3 +++ stdlib/3/asyncio/runners.pyi | 9 +++++++++ stdlib/3/asyncio/tasks.pyi | 8 +++++++- 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 stdlib/3/asyncio/runners.pyi diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index 6650910ea..6053f6b73 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -97,6 +97,20 @@ if sys.platform != 'win32': start_unix_server as start_unix_server, ) +if sys.version_info >= (3, 7): + from asyncio.events import ( + get_running_loop as get_running_loop, + ) + from asyncio.tasks import ( + all_tasks as all_tasks, + create_task as create_task, + current_task as current_task, + ) + from asyncio.runners import ( + run as run, + ) + + # TODO: It should be possible to instantiate these classes, but mypy # currently disallows this. # See https://github.com/python/mypy/issues/1843 diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index cc8e28e5d..15d9461a4 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -223,3 +223,6 @@ def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractCh def _set_running_loop(loop: AbstractEventLoop) -> None: ... def _get_running_loop() -> AbstractEventLoop: ... + +if sys.version_info >= (3, 7): + def get_running_loop() -> AbstractEventLoop: ... diff --git a/stdlib/3/asyncio/runners.pyi b/stdlib/3/asyncio/runners.pyi new file mode 100644 index 000000000..7d8c28c0d --- /dev/null +++ b/stdlib/3/asyncio/runners.pyi @@ -0,0 +1,9 @@ +import sys + + +if sys.version_info >= (3, 7): + from typing import Awaitable, TypeVar + + _T = TypeVar('_T') + + def run(main: Awaitable[_T], *, debug: bool = ...) -> _T: ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 15f5e2dbe..afc427886 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -1,8 +1,9 @@ +import concurrent.futures +import sys from typing import (Any, TypeVar, Set, Dict, List, TextIO, Union, Tuple, Generic, Callable, Coroutine, Generator, Iterable, Awaitable, overload, Sequence, Iterator, Optional) from types import FrameType -import concurrent.futures from .events import AbstractEventLoop from .futures import Future @@ -70,3 +71,8 @@ class Task(Future[_T], Generic[_T]): def cancel(self) -> bool: ... def _step(self, value: Any = ..., exc: Exception = ...) -> None: ... def _wakeup(self, future: Future[Any]) -> None: ... + +if sys.version_info >= (3, 7): + def all_tasks(loop: Optional[AbstractEventLoop] = ...) -> Set[Task]: ... + def create_task(coro: Union[Generator[Any, None, _T], Awaitable[_T]]) -> Task: ... + def current_task(loop: Optional[AbstractEventLoop] = ...) -> Optional[Task]: ...