diff --git a/stdlib/3/asyncio/__init__.pyi b/stdlib/3/asyncio/__init__.pyi index 43e3be9e2d1e..4a6c8ab2a00e 100644 --- a/stdlib/3/asyncio/__init__.pyi +++ b/stdlib/3/asyncio/__init__.pyi @@ -87,7 +87,9 @@ from asyncio.events import ( _set_running_loop as _set_running_loop, _get_running_loop as _get_running_loop, ) -if sys.platform != 'win32': +if sys.platform == 'win32': + from asyncio.windows_events import * +else: from asyncio.streams import ( open_unix_connection as open_unix_connection, start_unix_server as start_unix_server, @@ -111,8 +113,6 @@ if sys.version_info >= (3, 7): # currently disallows this. # See https://github.com/python/mypy/issues/1843 SelectorEventLoop: Type[AbstractEventLoop] -if sys.platform == 'win32': - ProactorEventLoop: Type[AbstractEventLoop] DefaultEventLoopPolicy: Type[AbstractEventLoopPolicy] # TODO: AbstractChildWatcher (UNIX only) diff --git a/stdlib/3/asyncio/base_events.pyi b/stdlib/3/asyncio/base_events.pyi index 8210ebded19a..79d32fab2c7c 100644 --- a/stdlib/3/asyncio/base_events.pyi +++ b/stdlib/3/asyncio/base_events.pyi @@ -11,6 +11,9 @@ from asyncio.protocols import BaseProtocol from asyncio.tasks import Task from asyncio.transports import BaseTransport +if sys.version_info >= (3, 7): + from contextvars import Context + _T = TypeVar('_T') _Context = Dict[str, Any] _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] @@ -37,9 +40,18 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): @coroutine def shutdown_asyncgens(self) -> Generator[Any, None, None]: ... # Methods scheduling callbacks. All these return Handles. - def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ... - def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... - def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... + if sys.version_info >= (3, 7): + def call_soon(self, callback: Callable[..., Any], *args: Any, context: Optional[Context] = ...) -> Handle: ... + def call_later( + self, delay: float, callback: Callable[..., Any], *args: Any, context: Optional[Context] = ..., + ) -> TimerHandle: ... + def call_at( + self, when: float, callback: Callable[..., Any], *args: Any, context: Optional[Context] = ..., + ) -> TimerHandle: ... + else: + def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ... + def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... + def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ... def time(self) -> float: ... # Future methods def create_future(self) -> Future[Any]: ... @@ -53,7 +65,10 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): def set_task_factory(self, factory: Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]) -> None: ... def get_task_factory(self) -> Optional[Callable[[AbstractEventLoop, Generator[Any, None, _T]], Future[_T]]]: ... # Methods for interacting with threads - def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ... + if sys.version_info >= (3, 7): + def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Optional[Context] = ...) -> Handle: ... + else: + def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ... @coroutine def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Generator[Any, None, _T]: ... @@ -67,9 +82,44 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): flags: int = ...) -> Generator[Any, None, List[Tuple[int, int, int, str, Tuple[Any, ...]]]]: ... @coroutine def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... - if sys.version_info >= (3, 7): - async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, - fallback: bool = ...) -> int: ... + if sys.version_info >= (3, 8): + @overload + async def create_connection( + self, + protocol_factory: _ProtocolFactory, + host: str = ..., + port: int = ..., + *, + ssl: _SSLContext = ..., + family: int = ..., + proto: int = ..., + flags: int = ..., + sock: None = ..., + local_addr: Optional[str] = ..., + server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ..., + happy_eyeballs_delay: Optional[float] = ..., + interleave: Optional[int] = ..., + ) -> _TransProtPair: ... + @overload + async def create_connection( + self, + protocol_factory: _ProtocolFactory, + host: None = ..., + port: None = ..., + *, + ssl: _SSLContext = ..., + family: int = ..., + proto: int = ..., + flags: int = ..., + sock: socket, + local_addr: None = ..., + server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ..., + happy_eyeballs_delay: Optional[float] = ..., + interleave: Optional[int] = ..., + ) -> _TransProtPair: ... + elif sys.version_info >= (3, 7): @overload async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., @@ -80,6 +130,20 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ..., ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + else: + @overload + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., + local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, + local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + if sys.version_info >= (3, 7): + async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... @overload async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., @@ -100,16 +164,6 @@ class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): else: @overload @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., - local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, - local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @coroutine def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., diff --git a/stdlib/3/asyncio/events.pyi b/stdlib/3/asyncio/events.pyi index 977bef092dee..5535ecb8a8d8 100644 --- a/stdlib/3/asyncio/events.pyi +++ b/stdlib/3/asyncio/events.pyi @@ -24,17 +24,22 @@ class Handle: def __repr__(self) -> str: ... def cancel(self) -> None: ... def _run(self) -> None: ... - def cancelled(self) -> bool: ... + if sys.version_info >= (3, 7): + def cancelled(self) -> bool: ... class TimerHandle(Handle): def __init__(self, when: float, callback: Callable[..., Any], args: List[Any], loop: AbstractEventLoop) -> None: ... def __hash__(self) -> int: ... + if sys.version_info >= (3, 7): + def when(self) -> float: ... class AbstractServer: sockets: Optional[List[socket]] def close(self) -> None: ... if sys.version_info >= (3, 7): + async def __aenter__(self: _T) -> _T: ... + async def __aexit__(self, *exc: Any) -> None: ... def get_loop(self) -> AbstractEventLoop: ... def is_serving(self) -> bool: ... async def start_serving(self) -> None: ... @@ -112,10 +117,46 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod @coroutine def getnameinfo(self, sockaddr: Tuple[Any, ...], flags: int = ...) -> Generator[Any, None, Tuple[str, int]]: ... - if sys.version_info >= (3, 7): + if sys.version_info >= (3, 8): + @overload @abstractmethod - async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, - fallback: bool = ...) -> int: ... + async def create_connection( + self, + protocol_factory: _ProtocolFactory, + host: str = ..., + port: int = ..., + *, + ssl: _SSLContext = ..., + family: int = ..., + proto: int = ..., + flags: int = ..., + sock: None = ..., + local_addr: Optional[str] = ..., + server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ..., + happy_eyeballs_delay: Optional[float] = ..., + interleave: Optional[int] = ..., + ) -> _TransProtPair: ... + @overload + @abstractmethod + async def create_connection( + self, + protocol_factory: _ProtocolFactory, + host: None = ..., + port: None = ..., + *, + ssl: _SSLContext = ..., + family: int = ..., + proto: int = ..., + flags: int = ..., + sock: socket, + local_addr: None = ..., + server_hostname: Optional[str] = ..., + ssl_handshake_timeout: Optional[float] = ..., + happy_eyeballs_delay: Optional[float] = ..., + interleave: Optional[int] = ..., + ) -> _TransProtPair: ... + elif sys.version_info >= (3, 7): @overload @abstractmethod async def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, @@ -128,6 +169,23 @@ class AbstractEventLoop(metaclass=ABCMeta): ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, local_addr: None = ..., server_hostname: Optional[str] = ..., ssl_handshake_timeout: Optional[float] = ...) -> _TransProtPair: ... + else: + @overload + @abstractmethod + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., + local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + @overload + @abstractmethod + @coroutine + def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, + ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, + local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... + if sys.version_info >= (3, 7): + @abstractmethod + async def sock_sendfile(self, sock: socket, file: IO[bytes], offset: int = ..., count: Optional[int] = ..., *, + fallback: bool = ...) -> int: ... @overload @abstractmethod async def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., @@ -162,18 +220,6 @@ class AbstractEventLoop(metaclass=ABCMeta): @overload @abstractmethod @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: str = ..., port: int = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: None = ..., - local_addr: Optional[str] = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @abstractmethod - @coroutine - def create_connection(self, protocol_factory: _ProtocolFactory, host: None = ..., port: None = ..., *, - ssl: _SSLContext = ..., family: int = ..., proto: int = ..., flags: int = ..., sock: socket, - local_addr: None = ..., server_hostname: Optional[str] = ...) -> Generator[Any, None, _TransProtPair]: ... - @overload - @abstractmethod - @coroutine def create_server(self, protocol_factory: _ProtocolFactory, host: Optional[Union[str, Sequence[str]]] = ..., port: int = ..., *, family: int = ..., flags: int = ..., sock: None = ..., backlog: int = ..., ssl: _SSLContext = ..., diff --git a/stdlib/3/asyncio/proactor_events.pyi b/stdlib/3/asyncio/proactor_events.pyi index bed374734f02..2cfa49de6ed7 100644 --- a/stdlib/3/asyncio/proactor_events.pyi +++ b/stdlib/3/asyncio/proactor_events.pyi @@ -1,9 +1,16 @@ - -from typing import Any, Mapping, Optional, Generator -from . import base_events, transports, events, streams, futures, constants +import sys from asyncio import coroutine from socket import socket -import sys +from typing import Any, Generator, Mapping, Optional, Union + +from . import base_events, constants, events, futures, streams, transports + +if sys.version_info >= (3, 7): + from os import PathLike + _Path = Union[str, PathLike[str]] +else: + _Path = str + if sys.version_info >= (3, 8): from typing import Literal else: @@ -45,12 +52,27 @@ class BaseProactorEventLoop(base_events.BaseEventLoop): # The methods below don't actually exist directly, ProactorEventLoops do not implement them. However, they are # needed to satisfy mypy if sys.version_info >= (3, 7): - async def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, ssl: events._SSLContext = ..., - sock: Optional[socket] = ..., server_hostname: str = ..., - ssl_handshake_timeout: Optional[float] = ...) -> events._TransProtPair: ... - async def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *, sock: Optional[socket] = ..., - backlog: int = ..., ssl: events._SSLContext = ..., ssl_handshake_timeout: Optional[float] = ..., - start_serving: bool = ...) -> events.AbstractServer: ... + async def create_unix_connection( + self, + protocol_factory: events._ProtocolFactory, + path: _Path, + *, + ssl: events._SSLContext = ..., + sock: Optional[socket] = ..., + server_hostname: str = ..., + ssl_handshake_timeout: Optional[float] = ..., + ) -> events._TransProtPair: ... + async def create_unix_server( + self, + protocol_factory: events._ProtocolFactory, + path: _Path, + *, + sock: Optional[socket] = ..., + backlog: int = ..., + ssl: events._SSLContext = ..., + ssl_handshake_timeout: Optional[float] = ..., + start_serving: bool = ..., + ) -> events.AbstractServer: ... else: @coroutine def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, diff --git a/stdlib/3/asyncio/selector_events.pyi b/stdlib/3/asyncio/selector_events.pyi index 42381de74005..c5edd79228da 100644 --- a/stdlib/3/asyncio/selector_events.pyi +++ b/stdlib/3/asyncio/selector_events.pyi @@ -1,21 +1,42 @@ - -from typing import Optional, Any, Generator -from . import base_events, events -from socket import socket -from asyncio import coroutine import selectors import sys +from asyncio import coroutine +from socket import socket +from typing import Any, Generator, Optional, Union + +from . import base_events, events + +if sys.version_info >= (3, 7): + from os import PathLike + _Path = Union[str, PathLike[str]] +else: + _Path = str class BaseSelectorEventLoop(base_events.BaseEventLoop): def __init__(self, selector: selectors.BaseSelector = ...) -> None: ... if sys.version_info >= (3, 7): - async def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, ssl: events._SSLContext = ..., - sock: Optional[socket] = ..., server_hostname: str = ..., - ssl_handshake_timeout: Optional[float] = ...) -> events._TransProtPair: ... - async def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *, sock: Optional[socket] = ..., - backlog: int = ..., ssl: events._SSLContext = ..., ssl_handshake_timeout: Optional[float] = ..., - start_serving: bool = ...) -> events.AbstractServer: ... + async def create_unix_connection( + self, + protocol_factory: events._ProtocolFactory, + path: _Path, + *, + ssl: events._SSLContext = ..., + sock: Optional[socket] = ..., + server_hostname: str = ..., + ssl_handshake_timeout: Optional[float] = ..., + ) -> events._TransProtPair: ... + async def create_unix_server( + self, + protocol_factory: events._ProtocolFactory, + path: _Path, + *, + sock: Optional[socket] = ..., + backlog: int = ..., + ssl: events._SSLContext = ..., + ssl_handshake_timeout: Optional[float] = ..., + start_serving: bool = ..., + ) -> events.AbstractServer: ... else: @coroutine def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *, diff --git a/stdlib/3/asyncio/streams.pyi b/stdlib/3/asyncio/streams.pyi index c3c8569ca5e2..5f5870b86c86 100644 --- a/stdlib/3/asyncio/streams.pyi +++ b/stdlib/3/asyncio/streams.pyi @@ -25,6 +25,7 @@ def open_connection( *, loop: Optional[events.AbstractEventLoop] = ..., limit: int = ..., + ssl_handshake_timeout: Optional[float] = ..., **kwds: Any ) -> Generator[Any, None, Tuple[StreamReader, StreamWriter]]: ... @@ -36,6 +37,7 @@ def start_server( *, loop: Optional[events.AbstractEventLoop] = ..., limit: int = ..., + ssl_handshake_timeout: Optional[float] = ..., **kwds: Any ) -> Generator[Any, None, events.AbstractServer]: ... diff --git a/stdlib/3/asyncio/tasks.pyi b/stdlib/3/asyncio/tasks.pyi index 65c28ebe68e5..28614687ab74 100644 --- a/stdlib/3/asyncio/tasks.pyi +++ b/stdlib/3/asyncio/tasks.pyi @@ -96,9 +96,19 @@ class Task(Future[_T], Generic[_T]): def current_task(cls, loop: Optional[AbstractEventLoop] = ...) -> Task[Any]: ... @classmethod def all_tasks(cls, loop: Optional[AbstractEventLoop] = ...) -> Set[Task[Any]]: ... - def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ... + if sys.version_info >= (3, 8): + def __init__( + self, + coro: Union[Generator[Any, None, _T], Awaitable[_T]], + *, + loop: AbstractEventLoop = ..., + name: Optional[str] = ..., + ) -> None: ... + else: + def __init__(self, coro: Union[Generator[Any, None, _T], Awaitable[_T]], *, loop: AbstractEventLoop = ...) -> None: ... def __repr__(self) -> str: ... if sys.version_info >= (3, 8): + def get_coro(self) -> Any: ... def get_name(self) -> str: ... def set_name(self, value: object) -> None: ... def get_stack(self, *, limit: int = ...) -> List[FrameType]: ...