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.
This commit is contained in:
Jelle Zijlstra
2023-11-07 19:26:25 -08:00
committed by GitHub
parent 4020d25686
commit b36f3c5229
7 changed files with 23 additions and 29 deletions

View File

@@ -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):

View File

@@ -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: ...

View File

@@ -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

View File

@@ -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__

View File

@@ -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__

View File

@@ -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

View File

@@ -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__