diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index eefc7b895436..acf392d97816 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -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- diff --git a/stdlib/asyncio/__init__.pyi b/stdlib/asyncio/__init__.pyi index 2f4823b22b24..24a86caed66e 100644 --- a/stdlib/asyncio/__init__.pyi +++ b/stdlib/asyncio/__init__.pyi @@ -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 * diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 7742651fea2a..310a9f585591 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -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 @@ -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, @@ -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, ...]: ... @@ -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]: ... @@ -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, @@ -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, @@ -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 @@ -250,8 +303,20 @@ 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], @@ -259,10 +324,43 @@ class BaseEventLoop(AbstractEventLoop): *, 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, @@ -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( @@ -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, @@ -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]: ... @@ -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: ... diff --git a/stdlib/asyncio/constants.pyi b/stdlib/asyncio/constants.pyi index 230cf4faf483..1fa643c7414b 100644 --- a/stdlib/asyncio/constants.pyi +++ b/stdlib/asyncio/constants.pyi @@ -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 diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index ae566234160b..8396f0957a1e 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -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,7 @@ class AbstractEventLoop: local_addr: 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: ... + if sys.version_info >= (3, 11): @overload @abstractmethod async def create_server( @@ -351,6 +397,7 @@ class AbstractEventLoop: reuse_address: bool | None = ..., reuse_port: bool | None = ..., ssl_handshake_timeout: float | None = ..., + ssl_shutdown_timeout: float | None = ..., start_serving: bool = ..., ) -> Server: ... @overload @@ -369,18 +416,21 @@ class 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 create_unix_connection( + @abstractmethod + async def start_tls( self, - protocol_factory: Callable[[], _ProtocolT], - path: str | None = ..., + transport: BaseTransport, + protocol: BaseProtocol, + sslcontext: ssl.SSLContext, *, - ssl: _SSLContext = ..., - sock: socket | None = ..., + server_side: bool = ..., server_hostname: str | None = ..., ssl_handshake_timeout: float | None = ..., - ) -> tuple[BaseTransport, _ProtocolT]: ... + ssl_shutdown_timeout: float | None = ..., + ) -> BaseTransport: ... async def create_unix_server( self, protocol_factory: _ProtocolFactory, @@ -390,12 +440,46 @@ class AbstractEventLoop: 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 sendfile( - self, transport: BaseTransport, file: IO[bytes], offset: int = ..., count: int | None = ..., *, fallback: bool = ... - ) -> 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 = ..., + 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 = ..., + start_serving: bool = ..., + ) -> Server: ... @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,24 +535,76 @@ class AbstractEventLoop: reuse_address: bool | None = ..., reuse_port: bool | None = ..., ) -> Server: ... + async def create_unix_server( + self, + protocol_factory: _ProtocolFactory, + path: str, + *, + sock: socket | None = ..., + 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, + 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]: ... - async def create_unix_server( + elif sys.version_info >= (3, 7): + async def create_unix_connection( self, - protocol_factory: _ProtocolFactory, - path: str, + protocol_factory: Callable[[], _ProtocolT], + path: str | None = ..., *, + ssl: _SSLContext = ..., sock: socket | None = ..., - backlog: int = ..., + 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 = ..., - ) -> Server: ... + 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: ... diff --git a/stdlib/asyncio/exceptions.pyi b/stdlib/asyncio/exceptions.pyi index a1bc2c16ab1f..075fbb805bb9 100644 --- a/stdlib/asyncio/exceptions.pyi +++ b/stdlib/asyncio/exceptions.pyi @@ -1,11 +1,24 @@ -__all__ = ( - "CancelledError", - "InvalidStateError", - "TimeoutError", - "IncompleteReadError", - "LimitOverrunError", - "SendfileNotAvailableError", -) +import sys + +if sys.version_info >= (3, 11): + __all__ = ( + "BrokenBarrierError", + "CancelledError", + "InvalidStateError", + "TimeoutError", + "IncompleteReadError", + "LimitOverrunError", + "SendfileNotAvailableError", + ) +else: + __all__ = ( + "CancelledError", + "InvalidStateError", + "TimeoutError", + "IncompleteReadError", + "LimitOverrunError", + "SendfileNotAvailableError", + ) class CancelledError(BaseException): ... class TimeoutError(Exception): ... @@ -20,3 +33,6 @@ class IncompleteReadError(EOFError): class LimitOverrunError(Exception): consumed: int def __init__(self, message: str, consumed: int) -> None: ... + +if sys.version_info >= (3, 11): + class BrokenBarrierError(RuntimeError): ... diff --git a/stdlib/asyncio/locks.pyi b/stdlib/asyncio/locks.pyi index 2758e0c46919..269602c7bc66 100644 --- a/stdlib/asyncio/locks.pyi +++ b/stdlib/asyncio/locks.pyi @@ -1,4 +1,6 @@ +import enum import sys +from _typeshed import Self from collections import deque from collections.abc import Callable, Generator from types import TracebackType @@ -8,7 +10,12 @@ from typing_extensions import Literal from .events import AbstractEventLoop from .futures import Future -if sys.version_info >= (3, 7): +if sys.version_info >= (3, 11): + from .mixins import _LoopBoundMixin + +if sys.version_info >= (3, 11): + __all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore", "Barrier") +elif sys.version_info >= (3, 7): __all__ = ("Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore") else: __all__ = ["Lock", "Event", "Condition", "Semaphore", "BoundedSemaphore"] @@ -40,20 +47,32 @@ else: ) -> None: ... class Lock(_ContextManagerMixin): - def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self) -> None: ... + else: + def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... + def locked(self) -> bool: ... async def acquire(self) -> Literal[True]: ... def release(self) -> None: ... class Event: - def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self) -> None: ... + else: + def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... + def is_set(self) -> bool: ... def set(self) -> None: ... def clear(self) -> None: ... async def wait(self) -> Literal[True]: ... class Condition(_ContextManagerMixin): - def __init__(self, lock: Lock | None = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self, lock: Lock | None = ...) -> None: ... + else: + def __init__(self, lock: Lock | None = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + def locked(self) -> bool: ... async def acquire(self) -> Literal[True]: ... def release(self) -> None: ... @@ -65,11 +84,39 @@ class Condition(_ContextManagerMixin): class Semaphore(_ContextManagerMixin): _value: int _waiters: deque[Future[Any]] - def __init__(self, value: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self, value: int = ...) -> None: ... + else: + def __init__(self, value: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + def locked(self) -> bool: ... async def acquire(self) -> Literal[True]: ... def release(self) -> None: ... def _wake_up_next(self) -> None: ... class BoundedSemaphore(Semaphore): - def __init__(self, value: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self, value: int = ...) -> None: ... + else: + def __init__(self, value: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + +if sys.version_info >= (3, 11): + class _BarrierState(enum.Enum): # undocumented + FILLING: str + DRAINING: str + RESETTING: str + BROKEN: str + + class Barrier(_LoopBoundMixin): + def __init__(self, parties: int) -> None: ... + async def __aenter__(self: Self) -> Self: ... + async def __aexit__(self, *args: object) -> None: ... + async def wait(self) -> int: ... + async def abort(self) -> None: ... + async def reset(self) -> None: ... + @property + def parties(self) -> int: ... + @property + def n_waiting(self) -> int: ... + @property + def broken(self) -> bool: ... diff --git a/stdlib/asyncio/mixins.pyi b/stdlib/asyncio/mixins.pyi index 4c11865c8968..3e04f2b37518 100644 --- a/stdlib/asyncio/mixins.pyi +++ b/stdlib/asyncio/mixins.pyi @@ -1,7 +1,9 @@ +import sys import threading from typing import NoReturn _global_lock: threading.Lock class _LoopBoundMixin: - def __init__(self, *, loop: NoReturn = ...) -> None: ... + if sys.version_info < (3, 11): + def __init__(self, *, loop: NoReturn = ...) -> None: ... diff --git a/stdlib/asyncio/queues.pyi b/stdlib/asyncio/queues.pyi index 93ea9d9fc6fe..0e1a0b2808df 100644 --- a/stdlib/asyncio/queues.pyi +++ b/stdlib/asyncio/queues.pyi @@ -16,7 +16,11 @@ class QueueFull(Exception): ... _T = TypeVar("_T") class Queue(Generic[_T]): - def __init__(self, maxsize: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + if sys.version_info >= (3, 11): + def __init__(self, maxsize: int = ...) -> None: ... + else: + def __init__(self, maxsize: int = ..., *, loop: AbstractEventLoop | None = ...) -> None: ... + def _init(self, maxsize: int) -> None: ... def _get(self) -> _T: ... def _put(self, item: _T) -> None: ... diff --git a/stdlib/asyncio/runners.pyi b/stdlib/asyncio/runners.pyi index 32cd839f2f79..49d236bbee9e 100644 --- a/stdlib/asyncio/runners.pyi +++ b/stdlib/asyncio/runners.pyi @@ -1,11 +1,28 @@ import sys -from collections.abc import Awaitable -from typing import TypeVar +from _typeshed import Self +from collections.abc import Callable, Coroutine +from contextvars import Context +from typing import Any, TypeVar -__all__ = ("run",) +from .events import AbstractEventLoop + +if sys.version_info >= (3, 11): + __all__ = ("Runner", "run") +else: + __all__ = ("run",) _T = TypeVar("_T") + +if sys.version_info >= (3, 11): + class Runner: + def __init__(self, *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ...) -> None: ... + def __enter__(self: Self) -> Self: ... + def __exit__(self, exc_type: object, exc_val: object, exc_tb: object) -> None: ... + def close(self) -> None: ... + def get_loop(self) -> AbstractEventLoop: ... + def run(self, coro: Coroutine[Any, Any, _T], *, context: Context | None = ...) -> _T: ... + if sys.version_info >= (3, 8): - def run(main: Awaitable[_T], *, debug: bool | None = ...) -> _T: ... + def run(main: Coroutine[Any, Any, _T], *, debug: bool | None = ...) -> _T: ... else: - def run(main: Awaitable[_T], *, debug: bool = ...) -> _T: ... + def run(main: Coroutine[Any, Any, _T], *, debug: bool = ...) -> _T: ... diff --git a/stdlib/asyncio/streams.pyi b/stdlib/asyncio/streams.pyi index 14a6d2c4d8fe..0f24d01d50cf 100644 --- a/stdlib/asyncio/streams.pyi +++ b/stdlib/asyncio/streams.pyi @@ -1,3 +1,4 @@ +import ssl import sys from _typeshed import Self, StrPath from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence @@ -179,6 +180,10 @@ class StreamWriter: def get_extra_info(self, name: str, default: Any = ...) -> Any: ... async def drain(self) -> None: ... + if sys.version_info >= (3, 11): + async def start_tls( + self, sslcontext: ssl.SSLContext, *, server_hostname: str | None = ..., ssl_handshake_timeout: float | None = ... + ) -> None: ... class StreamReader(AsyncIterator[bytes]): def __init__(self, limit: int = ..., loop: events.AbstractEventLoop | None = ...) -> None: ... diff --git a/stdlib/asyncio/taskgroups.pyi b/stdlib/asyncio/taskgroups.pyi index 58e3d41e53f1..9b2f15506c50 100644 --- a/stdlib/asyncio/taskgroups.pyi +++ b/stdlib/asyncio/taskgroups.pyi @@ -2,6 +2,7 @@ from _typeshed import Self from collections.abc import Coroutine, Generator +from contextvars import Context from types import TracebackType from typing import Any, TypeVar @@ -15,4 +16,6 @@ class TaskGroup: def __init__(self) -> None: ... async def __aenter__(self: Self) -> Self: ... async def __aexit__(self, et: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None: ... - def create_task(self, coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ... + def create_task( + self, coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ..., context: Context | None = ... + ) -> Task[_T]: ... diff --git a/stdlib/asyncio/tasks.pyi b/stdlib/asyncio/tasks.pyi index 4a8e565afb2f..2e483753a4d0 100644 --- a/stdlib/asyncio/tasks.pyi +++ b/stdlib/asyncio/tasks.pyi @@ -10,6 +10,8 @@ from .futures import Future if sys.version_info >= (3, 9): from types import GenericAlias +if sys.version_info >= (3, 11): + from contextvars import Context if sys.version_info >= (3, 7): __all__ = ( @@ -329,7 +331,11 @@ class Task(Future[_T], Generic[_T]): if sys.version_info >= (3, 7): def all_tasks(loop: AbstractEventLoop | None = ...) -> set[Task[Any]]: ... - if sys.version_info >= (3, 8): + if sys.version_info >= (3, 11): + def create_task( + coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ..., context: Context | None = ... + ) -> Task[_T]: ... + elif sys.version_info >= (3, 8): def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T], *, name: str | None = ...) -> Task[_T]: ... else: def create_task(coro: Generator[Any, None, _T] | Coroutine[Any, Any, _T]) -> Task[_T]: ... diff --git a/stdlib/asyncio/timeouts.pyi b/stdlib/asyncio/timeouts.pyi new file mode 100644 index 000000000000..be516b5851d1 --- /dev/null +++ b/stdlib/asyncio/timeouts.pyi @@ -0,0 +1,19 @@ +from _typeshed import Self +from types import TracebackType +from typing_extensions import final + +__all__ = ("Timeout", "timeout", "timeout_at") + +@final +class Timeout: + def __init__(self, when: float | None) -> None: ... + def when(self) -> float | None: ... + def reschedule(self, when: float | None) -> None: ... + def expired(self) -> bool: ... + async def __aenter__(self: Self) -> Self: ... + async def __aexit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None + ) -> None: ... + +def timeout(delay: float | None) -> Timeout: ... +def timeout_at(when: float | None) -> Timeout: ... diff --git a/tests/stubtest_allowlists/darwin-py311.txt b/tests/stubtest_allowlists/darwin-py311.txt index fcc44b18d8c5..dd278cb0911a 100644 --- a/tests/stubtest_allowlists/darwin-py311.txt +++ b/tests/stubtest_allowlists/darwin-py311.txt @@ -1,11 +1,5 @@ _?curses.A_ITALIC _?curses.color_pair -asyncio.SelectorEventLoop.create_unix_connection -asyncio.SelectorEventLoop.create_unix_server -asyncio.unix_events.SelectorEventLoop.create_unix_connection -asyncio.unix_events.SelectorEventLoop.create_unix_server -asyncio.unix_events._UnixSelectorEventLoop.create_unix_connection -asyncio.unix_events._UnixSelectorEventLoop.create_unix_server termios.tcgetwinsize termios.tcsetwinsize xxlimited.Xxo.x_exports diff --git a/tests/stubtest_allowlists/linux-py311.txt b/tests/stubtest_allowlists/linux-py311.txt index 9c9c3827710d..aad7b0f63742 100644 --- a/tests/stubtest_allowlists/linux-py311.txt +++ b/tests/stubtest_allowlists/linux-py311.txt @@ -1,10 +1,4 @@ _?curses.color_pair -asyncio.SelectorEventLoop.create_unix_connection -asyncio.SelectorEventLoop.create_unix_server -asyncio.unix_events.SelectorEventLoop.create_unix_connection -asyncio.unix_events.SelectorEventLoop.create_unix_server -asyncio.unix_events._UnixSelectorEventLoop.create_unix_connection -asyncio.unix_events._UnixSelectorEventLoop.create_unix_server distutils.command.build_ext.__warningregistry__ mmap.MAP_STACK (os|posix).EFD_CLOEXEC diff --git a/tests/stubtest_allowlists/py310.txt b/tests/stubtest_allowlists/py310.txt index 230f5ba8a4cc..53ef9a9ab040 100644 --- a/tests/stubtest_allowlists/py310.txt +++ b/tests/stubtest_allowlists/py310.txt @@ -88,8 +88,6 @@ _imp.source_hash ast.Tuple.dims ast.main asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this -asyncio.AbstractEventLoop.connect_accepted_socket -asyncio.events.AbstractEventLoop.connect_accepted_socket bdb.Breakpoint.clearBreakpoints distutils.dist.DistributionMetadata.set_classifiers distutils.dist.DistributionMetadata.set_keywords diff --git a/tests/stubtest_allowlists/py311.txt b/tests/stubtest_allowlists/py311.txt index 07c8c8a01896..131b07b650fa 100644 --- a/tests/stubtest_allowlists/py311.txt +++ b/tests/stubtest_allowlists/py311.txt @@ -29,75 +29,6 @@ ast.ImportFrom.level ast.Tuple.dims ast.main asynchat.__warningregistry__ # Removal planned for 3.12, can add if someone needs this -asyncio.AbstractEventLoop.connect_accepted_socket -asyncio.AbstractEventLoop.create_connection -asyncio.AbstractEventLoop.create_server -asyncio.AbstractEventLoop.create_task -asyncio.AbstractEventLoop.create_unix_connection -asyncio.AbstractEventLoop.create_unix_server -asyncio.AbstractEventLoop.sock_recvfrom -asyncio.AbstractEventLoop.sock_recvfrom_into -asyncio.AbstractEventLoop.sock_sendto -asyncio.AbstractEventLoop.start_tls -asyncio.Barrier -asyncio.BaseEventLoop.connect_accepted_socket -asyncio.BaseEventLoop.create_connection -asyncio.BaseEventLoop.create_server -asyncio.BaseEventLoop.create_task -asyncio.BaseEventLoop.start_tls -asyncio.BoundedSemaphore.__init__ -asyncio.BrokenBarrierError -asyncio.Condition.__init__ -asyncio.Event.__init__ -asyncio.Future.__init__ -asyncio.Lock.__init__ -asyncio.Queue.__init__ -asyncio.Runner -asyncio.Semaphore.__init__ -asyncio.Server.__init__ -asyncio.StreamWriter.start_tls -asyncio.TaskGroup.create_task -asyncio.Timeout -asyncio.base_events.BaseEventLoop.connect_accepted_socket -asyncio.base_events.BaseEventLoop.create_connection -asyncio.base_events.BaseEventLoop.create_server -asyncio.base_events.BaseEventLoop.create_task -asyncio.base_events.BaseEventLoop.start_tls -asyncio.base_events.Server.__init__ -asyncio.constants.FLOW_CONTROL_HIGH_WATER_SSL_READ -asyncio.constants.FLOW_CONTROL_HIGH_WATER_SSL_WRITE -asyncio.constants.SSL_SHUTDOWN_TIMEOUT -asyncio.create_task -asyncio.events.AbstractEventLoop.connect_accepted_socket -asyncio.events.AbstractEventLoop.create_connection -asyncio.events.AbstractEventLoop.create_server -asyncio.events.AbstractEventLoop.create_task -asyncio.events.AbstractEventLoop.create_unix_connection -asyncio.events.AbstractEventLoop.create_unix_server -asyncio.events.AbstractEventLoop.sock_recvfrom -asyncio.events.AbstractEventLoop.sock_recvfrom_into -asyncio.events.AbstractEventLoop.sock_sendto -asyncio.events.AbstractEventLoop.start_tls -asyncio.exceptions.BrokenBarrierError -asyncio.exceptions.__all__ -asyncio.futures.Future.__init__ -asyncio.locks.Barrier -asyncio.locks.BoundedSemaphore.__init__ -asyncio.locks.Condition.__init__ -asyncio.locks.Event.__init__ -asyncio.locks.Lock.__init__ -asyncio.locks.Semaphore.__init__ -asyncio.locks.__all__ -asyncio.mixins._LoopBoundMixin.__init__ -asyncio.proactor_events.BaseProactorEventLoop.sock_recvfrom -asyncio.proactor_events.BaseProactorEventLoop.sock_recvfrom_into -asyncio.proactor_events.BaseProactorEventLoop.sock_sendto -asyncio.queues.Queue.__init__ -asyncio.runners.Runner -asyncio.runners.__all__ -asyncio.selector_events.BaseSelectorEventLoop.sock_recvfrom -asyncio.selector_events.BaseSelectorEventLoop.sock_recvfrom_into -asyncio.selector_events.BaseSelectorEventLoop.sock_sendto asyncio.sslproto.AppProtocolState asyncio.sslproto.SSLAgainErrors asyncio.sslproto.SSLProtocol.__init__ @@ -110,11 +41,6 @@ asyncio.sslproto._SSLProtocolTransport.get_read_buffer_limits asyncio.sslproto._SSLProtocolTransport.get_read_buffer_size asyncio.sslproto._SSLProtocolTransport.set_read_buffer_limits asyncio.sslproto.add_flowcontrol_defaults -asyncio.streams.StreamWriter.start_tls -asyncio.taskgroups.TaskGroup.create_task -asyncio.tasks.create_task -asyncio.timeout -asyncio.timeout_at bdb.Breakpoint.clearBreakpoints binascii.a2b_base64 builtins.BaseException.add_note @@ -366,6 +292,8 @@ ast.Index.__new__ ast.NameConstant.__new__ ast.Num.__new__ ast.Str.__new__ +asyncio.futures.Future.__init__ +asyncio.Future.__init__ contextvars.Context.__init__ queue.SimpleQueue.__init__ xml.etree.ElementTree.XMLParser.__init__