Add type stubs for asyncio.unix_events (#3664)

* add 3.7 child watchers

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>

* add 3.8 child watchers

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>

* remove 3.7 check

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>

* fix too strict watcher return type in _UnixDefaultEventLoopPolicy.get_child_watcher

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>

* group asyncio imports

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>

* fixed platform check for importing from asyncio.unix_events

Signed-off-by: Oleg Höfling <oleg.hoefling@gmail.com>
This commit is contained in:
Oleg Höfling
2020-02-01 23:08:33 +01:00
committed by GitHub
parent 0db4897dab
commit 94fd3b5101
4 changed files with 71 additions and 7 deletions

View File

@@ -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 (

View File

@@ -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: ...

View File

@@ -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,

View File

@@ -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: ...