From b36f3c522910ae6c93b9fc894a6526e8b4919807 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 7 Nov 2023 19:26:25 -0800 Subject: [PATCH] asyncio: remove overly specific protocols (#10984) The _warn parameter to these methods is just there to work around some finalization issues and should never be used by users. In addition, these protocols are out of date (the "stacklevel" argument is not used by current CPython main). I don't think we gain anything by trying to maintain these protocol definitions. --- stdlib/asyncio/proactor_events.pyi | 13 ++----------- stdlib/asyncio/unix_events.pyi | 9 +-------- stdlib/asyncio/windows_utils.pyi | 12 ++---------- tests/stubtest_allowlists/darwin.txt | 5 +++++ tests/stubtest_allowlists/linux.txt | 5 +++++ tests/stubtest_allowlists/py3_common.txt | 4 ++++ tests/stubtest_allowlists/win32.txt | 4 ++++ 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/stdlib/asyncio/proactor_events.pyi b/stdlib/asyncio/proactor_events.pyi index 33fdf84ad..4634bbb2b 100644 --- a/stdlib/asyncio/proactor_events.pyi +++ b/stdlib/asyncio/proactor_events.pyi @@ -1,19 +1,13 @@ import sys from collections.abc import Mapping from socket import socket -from typing import Any, ClassVar, Protocol +from typing import Any, ClassVar from typing_extensions import Literal from . import base_events, constants, events, futures, streams, transports __all__ = ("BaseProactorEventLoop",) -if sys.version_info >= (3, 8): - class _WarnCallbackProtocol(Protocol): - def __call__( - self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ... - ) -> object: ... - class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport): def __init__( self, @@ -24,10 +18,7 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTr extra: Mapping[Any, Any] | None = None, server: events.AbstractServer | None = None, ) -> None: ... - if sys.version_info >= (3, 8): - def __del__(self, _warn: _WarnCallbackProtocol = ...) -> None: ... - else: - def __del__(self) -> None: ... + def __del__(self) -> None: ... class _ProactorReadPipeTransport(_ProactorBasePipeTransport, transports.ReadTransport): if sys.version_info >= (3, 10): diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index e28d64b52..dc3d3496a 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -84,13 +84,6 @@ if sys.platform != "win32": DefaultEventLoopPolicy = _UnixDefaultEventLoopPolicy if sys.version_info >= (3, 8): - from typing import Protocol - - class _Warn(Protocol): - def __call__( - self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ... - ) -> object: ... - class MultiLoopChildWatcher(AbstractChildWatcher): def is_active(self) -> bool: ... def close(self) -> None: ... @@ -109,7 +102,7 @@ if sys.platform != "win32": def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... - def __del__(self, _warn: _Warn = ...) -> None: ... + def __del__(self) -> None: ... def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... diff --git a/stdlib/asyncio/windows_utils.pyi b/stdlib/asyncio/windows_utils.pyi index 9f88718b7..ed5d8da27 100644 --- a/stdlib/asyncio/windows_utils.pyi +++ b/stdlib/asyncio/windows_utils.pyi @@ -2,16 +2,12 @@ import subprocess import sys from collections.abc import Callable from types import TracebackType -from typing import Any, AnyStr, Protocol +from typing import Any, AnyStr from typing_extensions import Literal, Self if sys.platform == "win32": __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") - class _WarnFunction(Protocol): - def __call__( - self, message: str, category: type[Warning] = ..., stacklevel: int = ..., source: PipeHandle = ... - ) -> object: ... BUFSIZE: Literal[8192] PIPE = subprocess.PIPE STDOUT = subprocess.STDOUT @@ -19,11 +15,7 @@ if sys.platform == "win32": class PipeHandle: def __init__(self, handle: int) -> None: ... - if sys.version_info >= (3, 8): - def __del__(self, _warn: _WarnFunction = ...) -> None: ... - else: - def __del__(self) -> None: ... - + def __del__(self) -> None: ... def __enter__(self) -> Self: ... def __exit__(self, t: type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ... @property diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index 014846d7c..f9e0cd1e6 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -65,3 +65,8 @@ curses.COLORS # Initialized after start_color curses.COLOR_PAIRS # Initialized after start_color curses.COLS # Initialized only after initscr call curses.LINES # Initialized only after initscr call + +# Takes a "_warn" parameter at runtime +# for technical reasons; no need to expose it in the stub. +asyncio.ThreadedChildWatcher.__del__ +asyncio.unix_events.ThreadedChildWatcher.__del__ diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 3e1993135..0d3ff2879 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -57,3 +57,8 @@ curses.COLORS # Initialized after start_color curses.COLOR_PAIRS # Initialized after start_color curses.COLS # Initialized only after initscr call curses.LINES # Initialized only after initscr call + +# Takes a "_warn" parameter at runtime +# for technical reasons; no need to expose it in the stub. +asyncio.ThreadedChildWatcher.__del__ +asyncio.unix_events.ThreadedChildWatcher.__del__ diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index c0e624182..4c414b2bd 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -374,6 +374,10 @@ threading.Condition.release multiprocessing.dummy.Condition.acquire multiprocessing.dummy.Condition.release +# Takes a "_warn" parameter at runtime +# for technical reasons; no need to expose it in the stub. +asyncio.proactor_events._ProactorBasePipeTransport.__del__ + # Weird special builtins that are typed as functions, but aren't functions builtins.copyright builtins.credits diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 0c783bea5..acf6f9bf8 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -60,3 +60,7 @@ pathlib.Path.group # but have yet to find their way to all GitHub Actions images (sys.get_int_max_str_digits)? (sys.set_int_max_str_digits)? + +# Takes a "_warn" parameter at runtime +# for technical reasons; no need to expose it in the stub. +asyncio.windows_utils.PipeHandle.__del__