From caa34dc98b755651f92329a4c70101e47c60272b Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Fri, 10 Nov 2023 18:33:06 +0000 Subject: [PATCH 1/6] Use PEP-646 in stubs for `asyncio` --- stdlib/asyncio/base_events.pyi | 27 ++++++++------ stdlib/asyncio/events.pyi | 65 ++++++++++++++++++++-------------- stdlib/asyncio/unix_events.pyi | 17 ++++----- 3 files changed, 64 insertions(+), 45 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index cdf295d510d4..e4b8c9f76850 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -11,7 +11,7 @@ from collections.abc import Callable, Iterable, Sequence from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, TypeVar, overload -from typing_extensions import Literal, TypeAlias +from typing_extensions import Literal, TypeAlias, TypeVarTuple, Unpack if sys.version_info >= (3, 9): __all__ = ("BaseEventLoop", "Server") @@ -19,6 +19,7 @@ else: __all__ = ("BaseEventLoop",) _T = TypeVar("_T") +_Ts = TypeVarTuple("_Ts") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) _Context: TypeAlias = dict[str, Any] _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object] @@ -71,13 +72,15 @@ class BaseEventLoop(AbstractEventLoop): def close(self) -> None: ... async def shutdown_asyncgens(self) -> None: ... # Methods scheduling callbacks. All these return Handles. - def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ... + def call_soon( + self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> Handle[Unpack[_Ts]]: ... def call_later( - self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = None - ) -> TimerHandle: ... + self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> TimerHandle[Unpack[_Ts]]: ... def call_at( - self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = None - ) -> TimerHandle: ... + self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> TimerHandle[Unpack[_Ts]]: ... def time(self) -> float: ... # Future methods def create_future(self) -> Future[Any]: ... @@ -92,8 +95,10 @@ class BaseEventLoop(AbstractEventLoop): def set_task_factory(self, factory: _TaskFactory | None) -> None: ... def get_task_factory(self) -> _TaskFactory | None: ... # Methods for interacting with threads - def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ... - def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ... + def call_soon_threadsafe( + self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> Handle[Unpack[_Ts]]: ... + def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... def set_default_executor(self, executor: Any) -> None: ... # Network I/O methods returning Futures. async def getaddrinfo( @@ -441,9 +446,9 @@ class BaseEventLoop(AbstractEventLoop): errors: None = None, **kwargs: Any, ) -> tuple[SubprocessTransport, _ProtocolT]: ... - def add_reader(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ... + def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ... def remove_reader(self, fd: FileDescriptorLike) -> bool: ... - def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ... + def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> 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. @@ -457,7 +462,7 @@ class BaseEventLoop(AbstractEventLoop): async def sock_recvfrom_into(self, sock: socket, buf: WriteableBuffer, nbytes: int = 0) -> tuple[int, _RetAddress]: ... async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ... # Signal handling. - def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ... + def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ... def remove_signal_handler(self, sig: int) -> bool: ... # Error handlers. def set_exception_handler(self, handler: _ExceptionHandler | None) -> None: ... diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 4c62043875ba..3e47df325ade 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -5,8 +5,8 @@ from abc import ABCMeta, abstractmethod from collections.abc import Callable, Coroutine, Generator, Sequence from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Protocol, TypeVar, overload -from typing_extensions import Literal, Self, TypeAlias +from typing import IO, Any, Generic, Protocol, TypeVar, overload +from typing_extensions import Literal, Self, TypeAlias, TypeVarTuple, Unpack from . import _AwaitableLike, _CoroutineLike from .base_events import Server @@ -56,6 +56,7 @@ else: ) _T = TypeVar("_T") +_Ts = TypeVarTuple("_Ts") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) _Context: TypeAlias = dict[str, Any] _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object] @@ -67,11 +68,15 @@ class _TaskFactory(Protocol): self, __loop: AbstractEventLoop, __factory: Coroutine[Any, Any, _T] | Generator[Any, None, _T] ) -> Future[_T]: ... -class Handle: +class Handle(Generic[Unpack[_Ts]]): _cancelled: bool - _args: Sequence[Any] + _args: tuple[Unpack[_Ts]] def __init__( - self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = None + self, + callback: Callable[[Unpack[_Ts]], object], + args: tuple[Unpack[_Ts]], + loop: AbstractEventLoop, + context: Context | None = None, ) -> None: ... def cancel(self) -> None: ... def _run(self) -> None: ... @@ -79,21 +84,21 @@ class Handle: if sys.version_info >= (3, 12): def get_context(self) -> Context: ... -class TimerHandle(Handle): +class TimerHandle(Handle[Unpack[_Ts]]): def __init__( self, when: float, - callback: Callable[..., object], - args: Sequence[Any], + callback: Callable[[Unpack[_Ts]], object], + args: tuple[Unpack[_Ts]], loop: AbstractEventLoop, context: Context | None = None, ) -> None: ... def __hash__(self) -> int: ... def when(self) -> float: ... - def __lt__(self, other: TimerHandle) -> bool: ... - def __le__(self, other: TimerHandle) -> bool: ... - def __gt__(self, other: TimerHandle) -> bool: ... - def __ge__(self, other: TimerHandle) -> bool: ... + def __lt__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... + def __le__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... + def __gt__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... + def __ge__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... def __eq__(self, other: object) -> bool: ... class AbstractServer: @@ -131,22 +136,28 @@ class AbstractEventLoop: # Methods scheduling callbacks. All these return Handles. if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2 @abstractmethod - def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ... + def call_soon( + self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> Handle[Unpack[_Ts]]: ... @abstractmethod def call_later( - self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = None - ) -> TimerHandle: ... + self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> TimerHandle[Unpack[_Ts]]: ... @abstractmethod def call_at( - self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = None - ) -> TimerHandle: ... + self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> TimerHandle[Unpack[_Ts]]: ... else: @abstractmethod - def call_soon(self, callback: Callable[..., object], *args: Any) -> Handle: ... + def call_soon(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle[Unpack[_Ts]]: ... @abstractmethod - def call_later(self, delay: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ... + def call_later( + self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts] + ) -> TimerHandle[Unpack[_Ts]]: ... @abstractmethod - def call_at(self, when: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ... + def call_at( + self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts] + ) -> TimerHandle[Unpack[_Ts]]: ... @abstractmethod def time(self) -> float: ... @@ -173,13 +184,15 @@ class AbstractEventLoop: # Methods for interacting with threads if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2 @abstractmethod - def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = None) -> Handle: ... + def call_soon_threadsafe( + self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None + ) -> Handle[Unpack[_Ts]]: ... else: @abstractmethod - def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any) -> Handle: ... + def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle[Unpack[_Ts]]: ... @abstractmethod - def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ... + def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... @abstractmethod def set_default_executor(self, executor: Any) -> None: ... # Network I/O methods returning Futures. @@ -542,11 +555,11 @@ class AbstractEventLoop: **kwargs: Any, ) -> tuple[SubprocessTransport, _ProtocolT]: ... @abstractmethod - def add_reader(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ... + def add_reader(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ... @abstractmethod def remove_reader(self, fd: FileDescriptorLike) -> bool: ... @abstractmethod - def add_writer(self, fd: FileDescriptorLike, callback: Callable[..., Any], *args: Any) -> None: ... + def add_writer(self, fd: FileDescriptorLike, callback: Callable[[Unpack[_Ts]], Any], *args: Unpack[_Ts]) -> None: ... @abstractmethod def remove_writer(self, fd: FileDescriptorLike) -> bool: ... # Completion based I/O methods returning Futures prior to 3.7 @@ -569,7 +582,7 @@ class AbstractEventLoop: async def sock_sendto(self, sock: socket, data: ReadableBuffer, address: _Address) -> int: ... # Signal handling. @abstractmethod - def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_signal_handler(self, sig: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... @abstractmethod def remove_signal_handler(self, sig: int) -> bool: ... # Error handlers. diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index dc3d3496ae55..aceff85bb718 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -2,18 +2,19 @@ import sys import types from abc import ABCMeta, abstractmethod from collections.abc import Callable -from typing import Any -from typing_extensions import Literal, Self +from typing_extensions import Literal, Self, TypeVarTuple, Unpack from .events import AbstractEventLoop, BaseDefaultEventLoopPolicy from .selector_events import BaseSelectorEventLoop +_Ts = TypeVarTuple("_Ts") + # This is also technically not available on Win, # but other parts of typeshed need this definition. # So, it is special cased. class AbstractChildWatcher: @abstractmethod - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... @abstractmethod def remove_child_handler(self, pid: int) -> bool: ... @abstractmethod @@ -65,13 +66,13 @@ if sys.platform != "win32": class SafeChildWatcher(BaseChildWatcher): def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... class FastChildWatcher(BaseChildWatcher): def __enter__(self) -> Self: ... def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... class _UnixSelectorEventLoop(BaseSelectorEventLoop): ... @@ -91,7 +92,7 @@ if sys.platform != "win32": def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... @@ -103,7 +104,7 @@ if sys.platform != "win32": self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... def __del__(self) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... @@ -116,5 +117,5 @@ if sys.platform != "win32": def is_active(self) -> bool: ... def close(self) -> None: ... def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... From 4b154604242ab1508c89b2f80c053bdc31a41529 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 14 Nov 2023 14:22:37 +0000 Subject: [PATCH 2/6] try to reduce fallout --- stdlib/asyncio/events.pyi | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 3e47df325ade..7024a5df5662 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -68,9 +68,9 @@ class _TaskFactory(Protocol): self, __loop: AbstractEventLoop, __factory: Coroutine[Any, Any, _T] | Generator[Any, None, _T] ) -> Future[_T]: ... -class Handle(Generic[Unpack[_Ts]]): +class Handle: _cancelled: bool - _args: tuple[Unpack[_Ts]] + _args: tuple[Any, ...] def __init__( self, callback: Callable[[Unpack[_Ts]], object], @@ -84,7 +84,7 @@ class Handle(Generic[Unpack[_Ts]]): if sys.version_info >= (3, 12): def get_context(self) -> Context: ... -class TimerHandle(Handle[Unpack[_Ts]]): +class TimerHandle(Handle): def __init__( self, when: float, @@ -95,10 +95,10 @@ class TimerHandle(Handle[Unpack[_Ts]]): ) -> None: ... def __hash__(self) -> int: ... def when(self) -> float: ... - def __lt__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... - def __le__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... - def __gt__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... - def __ge__(self, other: TimerHandle[Unpack[tuple[Any, ...]]]) -> bool: ... + def __lt__(self, other: TimerHandle) -> bool: ... + def __le__(self, other: TimerHandle) -> bool: ... + def __gt__(self, other: TimerHandle) -> bool: ... + def __ge__(self, other: TimerHandle) -> bool: ... def __eq__(self, other: object) -> bool: ... class AbstractServer: From 654d6b3dbdd1aa828a6d0dda662882d8dd6a6fa2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:23:18 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/asyncio/events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 7024a5df5662..ddf20b960d46 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -5,7 +5,7 @@ from abc import ABCMeta, abstractmethod from collections.abc import Callable, Coroutine, Generator, Sequence from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Generic, Protocol, TypeVar, overload +from typing import IO, Any, Protocol, TypeVar, overload from typing_extensions import Literal, Self, TypeAlias, TypeVarTuple, Unpack from . import _AwaitableLike, _CoroutineLike From c36f8cd118c10734df18593b0d24160ae2ed0e68 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 14 Nov 2023 14:28:21 +0000 Subject: [PATCH 4/6] fix --- stdlib/asyncio/base_events.pyi | 8 ++++---- stdlib/asyncio/events.pyi | 20 ++++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index e4b8c9f76850..522a7cc281ea 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -74,13 +74,13 @@ class BaseEventLoop(AbstractEventLoop): # Methods scheduling callbacks. All these return Handles. def call_soon( self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> Handle[Unpack[_Ts]]: ... + ) -> Handle: ... def call_later( self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> TimerHandle[Unpack[_Ts]]: ... + ) -> TimerHandle: ... def call_at( self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> TimerHandle[Unpack[_Ts]]: ... + ) -> TimerHandle: ... def time(self) -> float: ... # Future methods def create_future(self) -> Future[Any]: ... @@ -97,7 +97,7 @@ class BaseEventLoop(AbstractEventLoop): # Methods for interacting with threads def call_soon_threadsafe( self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> Handle[Unpack[_Ts]]: ... + ) -> Handle: ... def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... def set_default_executor(self, executor: Any) -> None: ... # Network I/O methods returning Futures. diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index ddf20b960d46..b78ba3a24641 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -138,26 +138,22 @@ class AbstractEventLoop: @abstractmethod def call_soon( self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> Handle[Unpack[_Ts]]: ... + ) -> Handle: ... @abstractmethod def call_later( self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> TimerHandle[Unpack[_Ts]]: ... + ) -> TimerHandle: ... @abstractmethod def call_at( self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> TimerHandle[Unpack[_Ts]]: ... + ) -> TimerHandle: ... else: @abstractmethod - def call_soon(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle[Unpack[_Ts]]: ... + def call_soon(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ... @abstractmethod - def call_later( - self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts] - ) -> TimerHandle[Unpack[_Ts]]: ... + def call_later(self, delay: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ... @abstractmethod - def call_at( - self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts] - ) -> TimerHandle[Unpack[_Ts]]: ... + def call_at(self, when: float, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> TimerHandle: ... @abstractmethod def time(self) -> float: ... @@ -186,10 +182,10 @@ class AbstractEventLoop: @abstractmethod def call_soon_threadsafe( self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts], context: Context | None = None - ) -> Handle[Unpack[_Ts]]: ... + ) -> Handle: ... else: @abstractmethod - def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle[Unpack[_Ts]]: ... + def call_soon_threadsafe(self, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> Handle: ... @abstractmethod def run_in_executor(self, executor: Any, func: Callable[[Unpack[_Ts]], _T], *args: Unpack[_Ts]) -> Future[_T]: ... From 738d58069e84118e50d42205ccc1da0873e91f81 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Fri, 17 Nov 2023 18:24:22 +0000 Subject: [PATCH 5/6] don't use PEP-646 for `(Timer)Handle` constructors --- stdlib/asyncio/events.pyi | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index b78ba3a24641..947e835879bf 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -70,13 +70,9 @@ class _TaskFactory(Protocol): class Handle: _cancelled: bool - _args: tuple[Any, ...] + _args: Sequence[Any] def __init__( - self, - callback: Callable[[Unpack[_Ts]], object], - args: tuple[Unpack[_Ts]], - loop: AbstractEventLoop, - context: Context | None = None, + self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = None ) -> None: ... def cancel(self) -> None: ... def _run(self) -> None: ... @@ -88,8 +84,8 @@ class TimerHandle(Handle): def __init__( self, when: float, - callback: Callable[[Unpack[_Ts]], object], - args: tuple[Unpack[_Ts]], + callback: Callable[..., object], + args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = None, ) -> None: ... From 70872eccf17bb6485146ca98fe33c7c45a91df9b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 26 Nov 2023 12:01:06 +0000 Subject: [PATCH 6/6] bad merge --- stdlib/asyncio/unix_events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/unix_events.pyi b/stdlib/asyncio/unix_events.pyi index 703896ce75b4..ee16035f86a8 100644 --- a/stdlib/asyncio/unix_events.pyi +++ b/stdlib/asyncio/unix_events.pyi @@ -138,7 +138,7 @@ if sys.platform != "win32": def __exit__( self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None ) -> None: ... - def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ... + def add_child_handler(self, pid: int, callback: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... def attach_loop(self, loop: AbstractEventLoop | None) -> None: ... elif sys.version_info >= (3, 8):