Skip to content

asyncio: updates for 3.11 #7844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4f10e38
asyncio.base_events: Add ssl_shutdown_timeout parameter
JelleZijlstra May 17, 2022
8303098
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 17, 2022
5d6a131
more constants
JelleZijlstra May 17, 2022
e6c44ee
events.pyi
JelleZijlstra May 17, 2022
f8206c1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 17, 2022
8174a7d
_ProtocolT is a TypeVar
JelleZijlstra May 17, 2022
c4d3fd5
connect_accepted_socket in base_events.pyi
JelleZijlstra May 17, 2022
c0b7afe
connect_accepted_socket was new in 3.10, says stubtest
JelleZijlstra May 17, 2022
dc561b5
remove allowlist
JelleZijlstra May 17, 2022
85f5f0a
Merge branch 'master' into JelleZijlstra-patch-1
JelleZijlstra May 17, 2022
8363f4b
I'll fix all this too
JelleZijlstra May 17, 2022
3b2ca50
Merge branch 'master' into JelleZijlstra-patch-1
hauntsaninja May 17, 2022
75f0de9
round of fixes
JelleZijlstra May 17, 2022
e6be9b4
isort
JelleZijlstra May 17, 2022
8f3162c
conditional import
JelleZijlstra May 17, 2022
2bf5175
imports
JelleZijlstra May 17, 2022
92b0172
fixes
JelleZijlstra May 17, 2022
d4a11a0
imports
JelleZijlstra May 17, 2022
db81fee
put them on the base class
JelleZijlstra May 17, 2022
ac7a36a
timeouts
JelleZijlstra May 17, 2022
5265ad8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 17, 2022
a51ed46
Use `typing_extensions.final`
AlexWaygood May 17, 2022
042c950
name is object
JelleZijlstra May 18, 2022
20a43e2
add comment
JelleZijlstra May 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ asyncio.runners: 3.7-
asyncio.staggered: 3.8-
asyncio.taskgroups: 3.11-
asyncio.threads: 3.9-
asyncio.timeouts: 3.11-
asyncio.trsock: 3.8-
asyncore: 2.7-
atexit: 2.7-
Expand Down
1 change: 1 addition & 0 deletions stdlib/asyncio/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if sys.version_info >= (3, 9):

if sys.version_info >= (3, 11):
from .taskgroups import *
from .timeouts import *

if sys.platform == "win32":
from .windows_events import *
Expand Down
147 changes: 133 additions & 14 deletions stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ssl
import sys
from _typeshed import FileDescriptorLike
from _typeshed import FileDescriptorLike, WriteableBuffer
from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle
from asyncio.futures import Future
from asyncio.protocols import BaseProtocol
Expand Down Expand Up @@ -29,7 +29,18 @@ _ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
_SSLContext: TypeAlias = bool | None | ssl.SSLContext

class Server(AbstractServer):
if sys.version_info >= (3, 7):
if sys.version_info >= (3, 11):
def __init__(
self,
loop: AbstractEventLoop,
sockets: Iterable[socket],
protocol_factory: _ProtocolFactory,
ssl_context: _SSLContext,
backlog: int,
ssl_handshake_timeout: float | None,
ssl_shutdown_timeout: float | None = ...,
) -> None: ...
elif sys.version_info >= (3, 7):
def __init__(
self,
loop: AbstractEventLoop,
Expand All @@ -39,12 +50,13 @@ class Server(AbstractServer):
backlog: int,
ssl_handshake_timeout: float | None,
) -> None: ...
else:
def __init__(self, loop: AbstractEventLoop, sockets: list[socket]) -> None: ...
if sys.version_info >= (3, 7):
def get_loop(self) -> AbstractEventLoop: ...
def is_serving(self) -> bool: ...
async def start_serving(self) -> None: ...
async def serve_forever(self) -> None: ...
else:
def __init__(self, loop: AbstractEventLoop, sockets: list[socket]) -> None: ...
if sys.version_info >= (3, 8):
@property
def sockets(self) -> tuple[socket, ...]: ...
Expand Down Expand Up @@ -86,7 +98,11 @@ class BaseEventLoop(AbstractEventLoop):
# Future methods
def create_future(self) -> Future[Any]: ...
# Tasks methods
if sys.version_info >= (3, 8):
if sys.version_info >= (3, 11):
def create_task(
self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T], *, name: object = ..., context: Context | None = ...
) -> Task[_T]: ...
elif sys.version_info >= (3, 8):
def create_task(self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T], *, name: object = ...) -> Task[_T]: ...
else:
def create_task(self, coro: Coroutine[Any, Any, _T] | Generator[Any, None, _T]) -> Task[_T]: ...
Expand All @@ -113,7 +129,46 @@ class BaseEventLoop(AbstractEventLoop):
flags: int = ...,
) -> list[tuple[AddressFamily, SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]: ...
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
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
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
async def create_connection(
self,
Expand Down Expand Up @@ -214,10 +269,7 @@ class BaseEventLoop(AbstractEventLoop):
local_addr: None = ...,
server_hostname: str | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
if sys.version_info >= (3, 7):
async def sock_sendfile(
self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ...
) -> int: ...
if sys.version_info >= (3, 11):
@overload
async def create_server(
self,
Expand All @@ -233,6 +285,7 @@ class BaseEventLoop(AbstractEventLoop):
reuse_address: bool | None = ...,
reuse_port: bool | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
@overload
Expand All @@ -250,19 +303,64 @@ class BaseEventLoop(AbstractEventLoop):
reuse_address: bool | None = ...,
reuse_port: bool | None = ...,
ssl_handshake_timeout: float | None = ...,
ssl_shutdown_timeout: float | None = ...,
start_serving: bool = ...,
) -> Server: ...
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 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]: ...
async def sendfile(
self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ...
) -> int: ...
elif sys.version_info >= (3, 7):
@overload
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 = ...,
start_serving: bool = ...,
) -> Server: ...
@overload
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 = ...,
start_serving: bool = ...,
) -> Server: ...
async def start_tls(
self,
transport: BaseTransport,
Expand All @@ -273,6 +371,14 @@ class BaseEventLoop(AbstractEventLoop):
server_hostname: str | None = ...,
ssl_handshake_timeout: float | None = ...,
) -> BaseTransport: ...
async def connect_accepted_socket(
self,
protocol_factory: Callable[[], _ProtocolT],
sock: socket,
*,
ssl: _SSLContext = ...,
ssl_handshake_timeout: float | None = ...,
) -> tuple[BaseTransport, _ProtocolT]: ...
else:
@overload
async def create_server(
Expand Down Expand Up @@ -307,6 +413,13 @@ class BaseEventLoop(AbstractEventLoop):
async def connect_accepted_socket(
self, protocol_factory: Callable[[], _ProtocolT], sock: socket, *, ssl: _SSLContext = ...
) -> tuple[BaseTransport, _ProtocolT]: ...
if sys.version_info >= (3, 7):
async def sock_sendfile(
self, sock: socket, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool | None = ...
) -> int: ...
async def sendfile(
self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ...
) -> int: ...
if sys.version_info >= (3, 11):
async def create_datagram_endpoint( # type: ignore[override]
self,
Expand Down Expand Up @@ -378,10 +491,12 @@ class BaseEventLoop(AbstractEventLoop):
def remove_reader(self, fd: FileDescriptorLike) -> bool: ...
def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ...
def remove_writer(self, fd: FileDescriptorLike) -> bool: ...
# The sock_* methods (and probably some others) are not actually implemented on
# BaseEventLoop, only on subclasses. We list them here for now for convenience.
# Completion based I/O methods returning Futures prior to 3.7
if sys.version_info >= (3, 7):
async def sock_recv(self, sock: socket, nbytes: int) -> bytes: ...
async def sock_recv_into(self, sock: socket, buf: bytearray) -> int: ...
async def sock_recv_into(self, sock: socket, buf: WriteableBuffer) -> int: ...
async def sock_sendall(self, sock: socket, data: bytes) -> None: ...
async def sock_connect(self, sock: socket, address: _Address) -> None: ...
async def sock_accept(self, sock: socket) -> tuple[socket, _RetAddress]: ...
Expand All @@ -390,6 +505,10 @@ class BaseEventLoop(AbstractEventLoop):
def sock_sendall(self, sock: socket, data: bytes) -> Future[None]: ...
def sock_connect(self, sock: socket, address: _Address) -> Future[None]: ...
def sock_accept(self, sock: socket) -> Future[tuple[socket, _RetAddress]]: ...
if sys.version_info >= (3, 11):
async def sock_recvfrom(self, sock: socket, bufsize: int) -> bytes: ...
async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = ...) -> int: ...
async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
# Signal handling.
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
def remove_signal_handler(self, sig: int) -> bool: ...
Expand Down
4 changes: 4 additions & 0 deletions stdlib/asyncio/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ DEBUG_STACK_DEPTH: Literal[10]
if sys.version_info >= (3, 7):
SSL_HANDSHAKE_TIMEOUT: float
SENDFILE_FALLBACK_READBUFFER_SIZE: Literal[262144]
if sys.version_info >= (3, 11):
SSL_SHUTDOWN_TIMEOUT: float
FLOW_CONTROL_HIGH_WATER_SSL_READ: Literal[256]
FLOW_CONTROL_HIGH_WATER_SSL_WRITE: Literal[512]

class _SendfileMode(enum.Enum):
UNSUPPORTED: int
Expand Down
Loading