From 63489c305d9db1159ce04a6d6542ec3932132939 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 13 Feb 2022 21:34:19 +0000 Subject: [PATCH] `asyncio`: make `AbstractServer` abstract and remove unnecessary metaclass=ABCMeta (#7185) --- stdlib/asyncio/base_events.pyi | 9 +++++++-- stdlib/asyncio/events.pyi | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 39c2d5003..4613581e2 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -1,7 +1,6 @@ import ssl import sys from _typeshed import FileDescriptorLike -from abc import ABCMeta from asyncio.events import AbstractEventLoop, AbstractServer, Handle, TimerHandle from asyncio.futures import Future from asyncio.protocols import BaseProtocol @@ -33,6 +32,10 @@ class Server(AbstractServer): backlog: int, ssl_handshake_timeout: float | None, ) -> None: ... + 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): @@ -43,8 +46,10 @@ class Server(AbstractServer): def sockets(self) -> list[socket]: ... else: sockets: list[socket] | None + def close(self) -> None: ... + async def wait_closed(self) -> None: ... -class BaseEventLoop(AbstractEventLoop, metaclass=ABCMeta): +class BaseEventLoop(AbstractEventLoop): def run_forever(self) -> None: ... # Can't use a union, see mypy issue # 1873. @overload diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 48c4b9d98..491410977 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -56,18 +56,24 @@ class TimerHandle(Handle): def when(self) -> float: ... class AbstractServer: + @abstractmethod def close(self) -> None: ... if sys.version_info >= (3, 7): async def __aenter__(self: Self) -> Self: ... async def __aexit__(self, *exc: Any) -> None: ... + @abstractmethod def get_loop(self) -> AbstractEventLoop: ... + @abstractmethod def is_serving(self) -> bool: ... + @abstractmethod async def start_serving(self) -> None: ... + @abstractmethod async def serve_forever(self) -> None: ... + @abstractmethod async def wait_closed(self) -> None: ... -class AbstractEventLoop(metaclass=ABCMeta): +class AbstractEventLoop: slow_callback_duration: float @abstractmethod def run_forever(self) -> None: ... @@ -491,7 +497,7 @@ class AbstractEventLoop(metaclass=ABCMeta): @abstractmethod async def shutdown_default_executor(self) -> None: ... -class AbstractEventLoopPolicy(metaclass=ABCMeta): +class AbstractEventLoopPolicy: @abstractmethod def get_event_loop(self) -> AbstractEventLoop: ... @abstractmethod