asyncio: updates for 3.11 (#7844)

CPython changes:

- 13c10bfb77
- 9523c0d84f
- 9f04ee569c
- d03acd7270
- 195a46d6ff

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra
2022-05-17 18:11:29 -07:00
committed by GitHub
parent ada3615a24
commit eab82c838a
18 changed files with 487 additions and 175 deletions

View File

@@ -1,6 +1,6 @@
import ssl
import sys
from _typeshed import FileDescriptorLike, Self
from _typeshed import FileDescriptorLike, Self, WriteableBuffer
from abc import ABCMeta, abstractmethod
from collections.abc import Awaitable, Callable, Coroutine, Generator, Sequence
from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket
@@ -184,7 +184,16 @@ class AbstractEventLoop:
@abstractmethod
def create_future(self) -> Future[Any]: ...
# Tasks methods
if sys.version_info >= (3, 8):
if sys.version_info >= (3, 11):
@abstractmethod
def create_task(
self,
coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T],
*,
name: str | None = ...,
context: Context | None = ...,
) -> Task[_T]: ...
elif sys.version_info >= (3, 8):
@abstractmethod
def create_task(
self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T], *, name: str | None = ...
@@ -223,7 +232,48 @@ class AbstractEventLoop:
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
@abstractmethod
async def getnameinfo(self, sockaddr: tuple[str, int] | tuple[str, int, int, int], flags: int = ...) -> tuple[str, str]: ...
if sys.version_info >= (3, 8):
if sys.version_info >= (3, 11):
@overload
@abstractmethod
async def create_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
host: str = ...,
port: int = ...,
*,
ssl: _SSLContext = ...,
family: int = ...,
proto: int = ...,
flags: int = ...,
sock: None = ...,
local_addr: tuple[str, int] | None = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
happy_eyeballs_delay: float | None = ...,
interleave: int | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
@overload
@abstractmethod
async def create_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
host: None = ...,
port: None = ...,
*,
ssl: _SSLContext = ...,
family: int = ...,
proto: int = ...,
flags: int = ...,
sock: socket,
local_addr: None = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
happy_eyeballs_delay: float | None = ...,
interleave: int | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
elif sys.version_info >= (3, 8):
@overload
@abstractmethod
async def create_connection(
@@ -330,11 +380,70 @@ class AbstractEventLoop:
local_addr: None = ...,
server_hostname: str | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
if sys.version_info >= (3, 7):
if sys.version_info >= (3, 11):
@overload
@abstractmethod
async def sock_sendfile(
self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ...
) -> int: ...
async def create_server(
self,
protocol_factory: _ProtocolFactory,
host: str | Sequence[str] | None = ...,
port: int = ...,
*,
family: int = ...,
flags: int = ...,
sock: None = ...,
backlog: int = ...,
ssl: _SSLContext = ...,
reuse_address: bool | None = ...,
reuse_port: bool | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
@overload
@abstractmethod
async def create_server(
self,
protocol_factory: _ProtocolFactory,
host: None = ...,
port: None = ...,
*,
family: int = ...,
flags: int = ...,
sock: socket = ...,
backlog: int = ...,
ssl: _SSLContext = ...,
reuse_address: bool | None = ...,
reuse_port: bool | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
@abstractmethod
async def start_tls(
self,
transport: BaseTransport,
protocol: BaseProtocol,
sslcontext: ssl.SSLContext,
*,
server_side: bool = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
) -> BaseTransport: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
path: str | None = ...,
*,
sock: socket | None = ...,
backlog: int = ...,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
elif sys.version_info >= (3, 7):
@overload
@abstractmethod
async def create_server(
@@ -371,31 +480,6 @@ class AbstractEventLoop:
ssl_handshake_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
async def create_unix_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
path: str | None = ...,
*,
ssl: _SSLContext = ...,
sock: socket | None = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
path: str | None = ...,
*,
sock: socket | None = ...,
backlog: int = ...,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
@abstractmethod
async def sendfile(
self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ...
) -> int: ...
@abstractmethod
async def start_tls(
self,
@@ -407,6 +491,17 @@ class AbstractEventLoop:
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
) -> BaseTransport: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
path: str | None = ...,
*,
sock: socket | None = ...,
backlog: int = ...,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
else:
@overload
@abstractmethod
@@ -440,15 +535,6 @@ class AbstractEventLoop:
reuse_address: bool | None = ...,
reuse_port: bool | None = ...,
) -> Server: ...
async def create_unix_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
path: str,
*,
ssl: _SSLContext = ...,
sock: socket | None = ...,
server_hostname: str | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
async def create_unix_server(
self,
protocol_factory: _ProtocolFactory,
@@ -458,6 +544,67 @@ class AbstractEventLoop:
backlog: int = ...,
ssl: _SSLContext = ...,
) -> Server: ...
if sys.version_info >= (3, 11):
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
sock: socket,
*,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
elif sys.version_info >= (3, 10):
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
sock: socket,
*,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
if sys.version_info >= (3, 11):
async def create_unix_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
path: str | None = ...,
*,
ssl: _SSLContext = ...,
sock: socket | None = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
elif sys.version_info >= (3, 7):
async def create_unix_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
path: str | None = ...,
*,
ssl: _SSLContext = ...,
sock: socket | None = ...,
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
else:
async def create_unix_connection(
self,
protocol_factory: Callable[[], _ProtocolT],
path: str,
*,
ssl: _SSLContext = ...,
sock: socket | None = ...,
server_hostname: str | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
if sys.version_info >= (3, 7):
@abstractmethod
async def sock_sendfile(
self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ...
) -> int: ...
@abstractmethod
async def sendfile(
self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ...
) -> int: ...
@abstractmethod
async def create_datagram_endpoint(
@@ -529,7 +676,7 @@ class AbstractEventLoop:
@abstractmethod
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
@abstractmethod
async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ...
@abstractmethod
async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
@abstractmethod
@@ -545,6 +692,13 @@ class AbstractEventLoop:
def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ...
@abstractmethod
def sock_accept(self, sock: socket) -> Future[tuple[socket, _RetAddress]]: ...
if sys.version_info >= (3, 11):
@abstractmethod
async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ...
@abstractmethod
async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = ...) -> int: ...
@abstractmethod
async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
# Signal handling.
@abstractmethod
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...