mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-06 20:24:30 +08:00
Add public missing asyncio stubs for windows and proactor files (#3234)
* Add public missing asyncio stubs for windows and proactor files, and any necessary private return/argument types. * Add methods to BaseProactorEventLoop that mypy is complaining about, with note about status at runtime * Add asyncio constants file
This commit is contained in:
committed by
Jelle Zijlstra
parent
6c42f6bb2f
commit
dfe68625ec
13
stdlib/3/asyncio/constants.pyi
Normal file
13
stdlib/3/asyncio/constants.pyi
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
import enum
|
||||
|
||||
LOG_THRESHOLD_FOR_CONNLOST_WRITES: int
|
||||
ACCEPT_RETRY_DELAY: int
|
||||
DEBUG_STACK_DEPTH: int
|
||||
SSL_HANDSHAKE_TIMEOUT: float
|
||||
SENDFILE_FALLBACK_READBUFFER_SIZE: int
|
||||
|
||||
class _SendfileMode(enum.Enum):
|
||||
UNSUPPORTED: int = ...
|
||||
TRY_NATIVE: int = ...
|
||||
FALLBACK: int = ...
|
||||
61
stdlib/3/asyncio/proactor_events.pyi
Normal file
61
stdlib/3/asyncio/proactor_events.pyi
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
from typing import Any, Mapping, Optional, Generator
|
||||
from . import base_events, transports, events, streams, futures, constants
|
||||
from asyncio import coroutine
|
||||
from socket import socket
|
||||
import sys
|
||||
if sys.version_info >= (3, 8):
|
||||
from typing import Literal
|
||||
else:
|
||||
from typing_extensions import Literal
|
||||
|
||||
class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport):
|
||||
|
||||
def __init__(self, loop: events.AbstractEventLoop, sock: socket, protocol: streams.StreamReaderProtocol, waiter: Optional[futures.Future[Any]] = ..., extra: Optional[Mapping[Any, Any]] = ..., server: Optional[events.AbstractServer] = ...) -> None: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __del__(self) -> None: ...
|
||||
def get_write_buffer_size(self) -> int: ...
|
||||
|
||||
class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport):
|
||||
|
||||
def __init__(self, loop: events.AbstractEventLoop, sock: socket, protocol: streams.StreamReaderProtocol, waiter: Optional[futures.Future[Any]] = ..., extra: Optional[Mapping[Any, Any]] = ..., server: Optional[events.AbstractServer] = ...) -> None: ...
|
||||
|
||||
class _ProactorBaseWritePipeTransport(_ProactorBasePipeTransport, transports.WriteTransport):
|
||||
|
||||
def __init__(self, loop: events.AbstractEventLoop, sock: socket, protocol: streams.StreamReaderProtocol, waiter: Optional[futures.Future[Any]] = ..., extra: Optional[Mapping[Any, Any]] = ..., server: Optional[events.AbstractServer] = ...) -> None: ...
|
||||
|
||||
class _ProactorWritePipeTransport(_ProactorBaseWritePipeTransport):
|
||||
|
||||
def __init__(self, loop: events.AbstractEventLoop, sock: socket, protocol: streams.StreamReaderProtocol, waiter: Optional[futures.Future[Any]] = ..., extra: Optional[Mapping[Any, Any]] = ..., server: Optional[events.AbstractServer] = ...) -> None: ...
|
||||
|
||||
class _ProactorDuplexPipeTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport): ...
|
||||
|
||||
class _ProactorSocketTransport(_ProactorReadPipeTransport, _ProactorBaseWritePipeTransport, transports.Transport):
|
||||
|
||||
_sendfile_compatible: constants._SendfileMode = ...
|
||||
|
||||
def __init__(self, loop: events.AbstractEventLoop, sock: socket, protocol: streams.StreamReaderProtocol, waiter: Optional[futures.Future[Any]] = ..., extra: Optional[Mapping[Any, Any]] = ..., server: Optional[events.AbstractServer] = ...) -> None: ...
|
||||
def _set_extra(self, sock: socket) -> None: ...
|
||||
def can_write_eof(self) -> Literal[True]: ...
|
||||
def write_eof(self) -> None: ...
|
||||
|
||||
class BaseProactorEventLoop(base_events.BaseEventLoop):
|
||||
|
||||
def __init__(self, proactor: Any) -> None: ...
|
||||
# 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: ...
|
||||
else:
|
||||
@coroutine
|
||||
def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *,
|
||||
ssl: events._SSLContext = ..., sock: Optional[socket] = ...,
|
||||
server_hostname: str = ...) -> Generator[Any, None, events._TransProtPair]: ...
|
||||
@coroutine
|
||||
def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *,
|
||||
sock: Optional[socket] = ..., backlog: int = ..., ssl: events._SSLContext = ...) -> Generator[Any, None, events.AbstractServer]: ...
|
||||
26
stdlib/3/asyncio/selector_events.pyi
Normal file
26
stdlib/3/asyncio/selector_events.pyi
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
from typing import Optional, Any, Generator
|
||||
from . import base_events, events
|
||||
from socket import socket
|
||||
from asyncio import coroutine
|
||||
import selectors
|
||||
import sys
|
||||
|
||||
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: ...
|
||||
else:
|
||||
@coroutine
|
||||
def create_unix_connection(self, protocol_factory: events._ProtocolFactory, path: str, *,
|
||||
ssl: events._SSLContext = ..., sock: Optional[socket] = ...,
|
||||
server_hostname: str = ...) -> Generator[Any, None, events._TransProtPair]: ...
|
||||
@coroutine
|
||||
def create_unix_server(self, protocol_factory: events._ProtocolFactory, path: str, *,
|
||||
sock: Optional[socket] = ..., backlog: int = ..., ssl: events._SSLContext = ...) -> Generator[Any, None, events.AbstractServer]: ...
|
||||
@@ -1,6 +1,7 @@
|
||||
import sys
|
||||
from typing import Any, Mapping, List, Optional, Tuple
|
||||
from asyncio.protocols import BaseProtocol
|
||||
from asyncio.events import AbstractEventLoop
|
||||
|
||||
class BaseTransport:
|
||||
def __init__(self, extra: Mapping[Any, Any] = ...) -> None: ...
|
||||
@@ -41,3 +42,7 @@ class SubprocessTransport(BaseTransport):
|
||||
def send_signal(self, signal: int) -> int: ...
|
||||
def terminate(self) -> None: ...
|
||||
def kill(self) -> None: ...
|
||||
|
||||
class _FlowControlMixin(Transport):
|
||||
def __init__(self, extra: Optional[Mapping[Any, Any]] = ..., loop: Optional[AbstractEventLoop] = ...) -> None: ...
|
||||
def get_write_buffer_limits(self) -> Tuple[int, int]: ...
|
||||
|
||||
58
stdlib/3/asyncio/windows_events.pyi
Normal file
58
stdlib/3/asyncio/windows_events.pyi
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
from typing import Callable, Tuple, List, IO, Any, Optional
|
||||
import socket
|
||||
from . import proactor_events, events, futures, windows_utils, selector_events, streams
|
||||
|
||||
NULL: int
|
||||
INFINITE: int
|
||||
ERROR_CONNECTION_REFUSED: int
|
||||
ERROR_CONNECTION_ABORTED: int
|
||||
CONNECT_PIPE_INIT_DELAY: float
|
||||
CONNECT_PIPE_MAX_DELAY: float
|
||||
|
||||
class PipeServer:
|
||||
|
||||
def __init__(self, address: str) -> None: ...
|
||||
def __del__(self) -> None: ...
|
||||
def closed(self) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
class _WindowsSelectorEventLoop(selector_events.BaseSelectorEventLoop): ...
|
||||
|
||||
class ProactorEventLoop(proactor_events.BaseProactorEventLoop):
|
||||
|
||||
def __init__(self, proactor: Optional[IocpProactor] = ...) -> None: ...
|
||||
async def create_pipe_connection(self, protocol_factory: Callable[[], streams.StreamReaderProtocol], address: str) -> Tuple[proactor_events._ProactorDuplexPipeTransport, streams.StreamReaderProtocol]: ...
|
||||
async def start_serving_pipe(self, protocol_factory: Callable[[], streams.StreamReaderProtocol], address: str) -> List[PipeServer]: ...
|
||||
|
||||
class IocpProactor:
|
||||
|
||||
def __init__(self, concurrency: int = ...) -> None: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __del__(self) -> None: ...
|
||||
def set_loop(self, loop: events.AbstractEventLoop) -> None: ...
|
||||
def select(self, timeout: Optional[int] = ...) -> List[futures.Future[Any]]: ...
|
||||
def recv(self, conn: socket.socket, nbytes: int, flags: int = ...) -> futures.Future[bytes]: ...
|
||||
def recv_into(self, conn: socket.socket, buf: socket._WriteBuffer, flags: int = ...) -> futures.Future[Any]: ...
|
||||
def send(self, conn: socket.socket, buf: socket._WriteBuffer, flags: int = ...) -> futures.Future[Any]: ...
|
||||
def accept(self, listener: socket.socket) -> futures.Future[Any]: ...
|
||||
def connect(self, conn: socket.socket, address: bytes) -> futures.Future[Any]: ...
|
||||
def sendfile(self, sock: socket.socket, file: IO[bytes], offset: int, count: int) -> futures.Future[Any]: ...
|
||||
def accept_pipe(self, pipe: socket.socket) -> futures.Future[Any]: ...
|
||||
async def connect_pipe(self, address: bytes) -> windows_utils.PipeHandle: ...
|
||||
def wait_for_handle(self, handle: windows_utils.PipeHandle, timeout: int = ...) -> bool: ...
|
||||
def close(self) -> None: ...
|
||||
|
||||
SelectorEventLoop = _WindowsSelectorEventLoop
|
||||
|
||||
class WindowsSelectorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
||||
_loop_factory: events.AbstractEventLoop = ...
|
||||
def get_child_watcher(self) -> Any: ...
|
||||
def set_child_watcher(self, watcher: Any) -> None: ...
|
||||
|
||||
class WindowsProactorEventLoopPolicy(events.BaseDefaultEventLoopPolicy):
|
||||
_loop_factory: events.AbstractEventLoop = ...
|
||||
def get_child_watcher(self) -> Any: ...
|
||||
def set_child_watcher(self, watcher: Any) -> None: ...
|
||||
|
||||
DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy
|
||||
21
stdlib/3/asyncio/windows_utils.pyi
Normal file
21
stdlib/3/asyncio/windows_utils.pyi
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
from typing import Tuple, Callable, Optional
|
||||
from types import TracebackType
|
||||
|
||||
BUFSIZE: int = ...
|
||||
PIPE: int = ...
|
||||
STDOUT: int = ...
|
||||
|
||||
def pipe(*, duplex: bool = ..., overlapped: Tuple[bool, bool] = ..., bufsize: int = ...) -> Tuple[int, int]: ...
|
||||
|
||||
class PipeHandle:
|
||||
|
||||
def __init__(self, handle: int) -> None: ...
|
||||
def __repr__(self) -> str: ...
|
||||
def __del__(self) -> None: ...
|
||||
def __enter__(self) -> PipeHandle: ...
|
||||
def __exit__(self, t: Optional[type], v: Optional[BaseException], tb: Optional[TracebackType]) -> None: ...
|
||||
@property
|
||||
def handle(self) -> int: ...
|
||||
def fileno(self) -> int: ...
|
||||
def close(self, *, CloseHandle: Callable[[int], None] = ...) -> None: ...
|
||||
Reference in New Issue
Block a user