diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index 8ba093616..eb2b021de 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -112,8 +112,13 @@ if sys.version_info >= (3, 7): if sys.platform != 'win32': # This is already imported above on Windows. SelectorEventLoop: Type[AbstractEventLoop] - -# TODO: AbstractChildWatcher (UNIX only) + from .unix_events import ( + AbstractChildWatcher as AbstractChildWatcher, + BaseChildWatcher as BaseChildWatcher, + SafeChildWatcher as SafeChildWatcher, + ) + if sys.version_info >= (3, 8): + from .unix_events import MultiLoopChildWatcher as MultiLoopChildWatcher, ThreadedChildWatcher as ThreadedChildWatcher if sys.version_info >= (3, 8): from asyncio.exceptions import ( diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index d4e0e5762..f90c98cbe 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -7,6 +7,8 @@ from asyncio.futures import Future from asyncio.protocols import BaseProtocol from asyncio.tasks import Task from asyncio.transports import BaseTransport +from asyncio.unix_events import AbstractChildWatcher + from _types import FileDescriptorLike _T = TypeVar('_T') @@ -310,9 +312,9 @@ class AbstractEventLoopPolicy(metaclass=ABCMeta): def new_event_loop(self) -> AbstractEventLoop: ... # Child processes handling (Unix only). @abstractmethod - def get_child_watcher(self) -> Any: ... # TODO: unix_events.AbstractChildWatcher + def get_child_watcher(self) -> AbstractChildWatcher: ... @abstractmethod - def set_child_watcher(self, watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher + def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ... class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy, metaclass=ABCMeta): def __init__(self) -> None: ... @@ -327,8 +329,8 @@ def get_event_loop() -> AbstractEventLoop: ... def set_event_loop(loop: Optional[AbstractEventLoop]) -> None: ... def new_event_loop() -> AbstractEventLoop: ... -def get_child_watcher() -> Any: ... # TODO: unix_events.AbstractChildWatcher -def set_child_watcher(watcher: Any) -> None: ... # TODO: unix_events.AbstractChildWatcher +def get_child_watcher() -> AbstractChildWatcher: ... +def set_child_watcher(watcher: AbstractChildWatcher) -> None: ... def _set_running_loop(loop: Optional[AbstractEventLoop]) -> None: ... def _get_running_loop() -> AbstractEventLoop: ... diff --git a/stdlib/3/asyncio/selector_events.pyi b/stdlib/3/asyncio/selector_events.pyi index 7c3f74fcf..5d63cdf8f 100644 --- a/stdlib/3/asyncio/selector_events.pyi +++ b/stdlib/3/asyncio/selector_events.pyi @@ -13,7 +13,7 @@ else: class BaseSelectorEventLoop(base_events.BaseEventLoop): - def __init__(self, selector: selectors.BaseSelector = ...) -> None: ... + def __init__(self, selector: Optional[selectors.BaseSelector] = ...) -> None: ... if sys.version_info >= (3, 7): async def create_unix_connection( self, diff --git a/stdlib/3/asyncio/unix_events.pyi b/stdlib/3/asyncio/unix_events.pyi new file mode 100644 index 000000000..310435d7a --- /dev/null +++ b/stdlib/3/asyncio/unix_events.pyi @@ -0,0 +1,57 @@ +import sys +import types +from typing import Any, Callable, Optional, Type, TypeVar + +from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy +from .selector_events import BaseSelectorEventLoop + +_T1 = TypeVar('_T1', bound=AbstractChildWatcher) +_T2 = TypeVar('_T2', bound=SafeChildWatcher) +_T3 = TypeVar('_T3', bound=FastChildWatcher) + +class AbstractChildWatcher: + def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ... + def remove_child_handler(self, pid: int) -> None: ... + def attach_loop(self, loop: Optional[AbstractEventLoop]) -> None: ... + def close(self) -> None: ... + def __enter__(self: _T1) -> _T1: ... + def __exit__( + self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType] + ) -> None: ... + if sys.version_info >= (3, 8): + def is_active(self) -> bool: ... + +class BaseChildWatcher(AbstractChildWatcher): + def __init__(self) -> None: ... + +class SafeChildWatcher(BaseChildWatcher): + def __enter__(self: _T2) -> _T2: ... + +class FastChildWatcher(BaseChildWatcher): + def __enter__(self: _T3) -> _T3: ... + +class _UnixSelectorEventLoop(BaseSelectorEventLoop): ... + +class _UnixDefaultEventLoopPolicy(BaseDefaultEventLoopPolicy): + def get_child_watcher(self) -> AbstractChildWatcher: ... + def set_child_watcher(self, watcher: Optional[AbstractChildWatcher]) -> None: ... + +SelectorEventLoop = _UnixSelectorEventLoop + +DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy + +if sys.version_info >= (3, 8): + + from typing import Protocol + + _T4 = TypeVar('_T4', bound=MultiLoopChildWatcher) + _T5 = TypeVar('_T5', bound=ThreadedChildWatcher) + class _Warn(Protocol): + def __call__( + self, message: str, category: Optional[Type[Warning]] = ..., stacklevel: int = ..., source: Optional[Any] = ... + ) -> None: ... + class MultiLoopChildWatcher(AbstractChildWatcher): + def __enter__(self: _T4) -> _T4: ... + class ThreadedChildWatcher(AbstractChildWatcher): + def __enter__(self: _T5) -> _T5: ... + def __del__(self, _warn: _Warn = ...) -> None: ...