Skip to content

Commit 4b504c7

Browse files
authored
Improve asyncio callbacks (#8192)
1 parent 9519e36 commit 4b504c7

8 files changed

+31
-31
lines changed

stdlib/asyncio/base_events.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ else:
2020
_T = TypeVar("_T")
2121
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
2222
_Context: TypeAlias = dict[str, Any]
23-
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
23+
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
2424
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
2525
_SSLContext: TypeAlias = bool | None | ssl.SSLContext
2626

@@ -74,11 +74,11 @@ class BaseEventLoop(AbstractEventLoop):
7474
def close(self) -> None: ...
7575
async def shutdown_asyncgens(self) -> None: ...
7676
# Methods scheduling callbacks. All these return Handles.
77-
def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
77+
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
7878
def call_later(
79-
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
79+
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
8080
) -> TimerHandle: ...
81-
def call_at(self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> TimerHandle: ...
81+
def call_at(self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> TimerHandle: ...
8282
def time(self) -> float: ...
8383
# Future methods
8484
def create_future(self) -> Future[Any]: ...
@@ -95,7 +95,7 @@ class BaseEventLoop(AbstractEventLoop):
9595
def set_task_factory(self, factory: _TaskFactory | None) -> None: ...
9696
def get_task_factory(self) -> _TaskFactory | None: ...
9797
# Methods for interacting with threads
98-
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
98+
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
9999
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
100100
def set_default_executor(self, executor: Any) -> None: ...
101101
# Network I/O methods returning Futures.

stdlib/asyncio/base_subprocess.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
5656
def terminate(self) -> None: ...
5757
def kill(self) -> None: ...
5858
async def _connect_pipes(self, waiter: futures.Future[Any] | None) -> None: ... # undocumented
59-
def _call(self, cb: Callable[..., Any], *data: Any) -> None: ... # undocumented
59+
def _call(self, cb: Callable[..., object], *data: Any) -> None: ... # undocumented
6060
def _pipe_connection_lost(self, fd: int, exc: BaseException | None) -> None: ... # undocumented
6161
def _pipe_data_received(self, fd: int, data: bytes) -> None: ... # undocumented
6262
def _process_exited(self, returncode: int) -> None: ... # undocumented

stdlib/asyncio/events.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ else:
5757
_T = TypeVar("_T")
5858
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
5959
_Context: TypeAlias = dict[str, Any]
60-
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
60+
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
6161
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
6262
_SSLContext: TypeAlias = bool | None | ssl.SSLContext
6363

@@ -70,7 +70,7 @@ class Handle:
7070
_cancelled: bool
7171
_args: Sequence[Any]
7272
def __init__(
73-
self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
73+
self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
7474
) -> None: ...
7575
def cancel(self) -> None: ...
7676
def _run(self) -> None: ...
@@ -80,7 +80,7 @@ class TimerHandle(Handle):
8080
def __init__(
8181
self,
8282
when: float,
83-
callback: Callable[..., Any],
83+
callback: Callable[..., object],
8484
args: Sequence[Any],
8585
loop: AbstractEventLoop,
8686
context: Context | None = ...,
@@ -133,22 +133,22 @@ class AbstractEventLoop:
133133
# Methods scheduling callbacks. All these return Handles.
134134
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
135135
@abstractmethod
136-
def call_soon(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
136+
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
137137
@abstractmethod
138138
def call_later(
139-
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
139+
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
140140
) -> TimerHandle: ...
141141
@abstractmethod
142142
def call_at(
143-
self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
143+
self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
144144
) -> TimerHandle: ...
145145
else:
146146
@abstractmethod
147-
def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
147+
def call_soon(self, callback: Callable[..., object], *args: Any) -> Handle: ...
148148
@abstractmethod
149-
def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
149+
def call_later(self, delay: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
150150
@abstractmethod
151-
def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
151+
def call_at(self, when: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
152152

153153
@abstractmethod
154154
def time(self) -> float: ...
@@ -181,10 +181,10 @@ class AbstractEventLoop:
181181
# Methods for interacting with threads
182182
if sys.version_info >= (3, 9): # "context" added in 3.9.10/3.10.2
183183
@abstractmethod
184-
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
184+
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
185185
else:
186186
@abstractmethod
187-
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
187+
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any) -> Handle: ...
188188

189189
@abstractmethod
190190
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
@@ -577,7 +577,7 @@ class AbstractEventLoop:
577577
async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
578578
# Signal handling.
579579
@abstractmethod
580-
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
580+
def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ...
581581
@abstractmethod
582582
def remove_signal_handler(self, sig: int) -> bool: ...
583583
# Error handlers.

stdlib/asyncio/futures.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Future(Awaitable[_T], Iterable[_T]):
4444
def get_loop(self) -> AbstractEventLoop: ...
4545
@property
4646
def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ...
47-
def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ...
47+
def add_done_callback(self: Self, __fn: Callable[[Self], object], *, context: Context | None = ...) -> None: ...
4848
if sys.version_info >= (3, 9):
4949
def cancel(self, msg: Any | None = ...) -> bool: ...
5050
else:
@@ -54,7 +54,7 @@ class Future(Awaitable[_T], Iterable[_T]):
5454
def done(self) -> bool: ...
5555
def result(self) -> _T: ...
5656
def exception(self) -> BaseException | None: ...
57-
def remove_done_callback(self: Self, __fn: Callable[[Self], Any]) -> int: ...
57+
def remove_done_callback(self: Self, __fn: Callable[[Self], object]) -> int: ...
5858
def set_result(self, __result: _T) -> None: ...
5959
def set_exception(self, __exception: type | BaseException) -> None: ...
6060
def __iter__(self) -> Generator[Any, None, _T]: ...

stdlib/asyncio/proactor_events.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if sys.version_info >= (3, 8):
1212
class _WarnCallbackProtocol(Protocol):
1313
def __call__(
1414
self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...
15-
) -> None: ...
15+
) -> object: ...
1616

1717
class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport):
1818
def __init__(

stdlib/asyncio/sslproto.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ if sys.version_info < (3, 11):
5757
def need_ssldata(self) -> bool: ...
5858
@property
5959
def wrapped(self) -> bool: ...
60-
def do_handshake(self, callback: Callable[[BaseException | None], None] | None = ...) -> list[bytes]: ...
61-
def shutdown(self, callback: Callable[[], None] | None = ...) -> list[bytes]: ...
60+
def do_handshake(self, callback: Callable[[BaseException | None], object] | None = ...) -> list[bytes]: ...
61+
def shutdown(self, callback: Callable[[], object] | None = ...) -> list[bytes]: ...
6262
def feed_eof(self) -> None: ...
6363
def feed_ssldata(self, data: bytes, only_handshake: bool = ...) -> tuple[list[bytes], list[bytes]]: ...
6464
def feed_appdata(self, data: bytes, offset: int = ...) -> tuple[list[bytes], int]: ...

stdlib/asyncio/unix_events.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ from .selector_events import BaseSelectorEventLoop
1414
# So, it is special cased.
1515
class AbstractChildWatcher:
1616
@abstractmethod
17-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
17+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
1818
@abstractmethod
1919
def remove_child_handler(self, pid: int) -> bool: ...
2020
@abstractmethod
@@ -67,13 +67,13 @@ if sys.platform != "win32":
6767
class SafeChildWatcher(BaseChildWatcher):
6868
def __enter__(self: Self) -> Self: ...
6969
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
70-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
70+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
7171
def remove_child_handler(self, pid: int) -> bool: ...
7272

7373
class FastChildWatcher(BaseChildWatcher):
7474
def __enter__(self: Self) -> Self: ...
7575
def __exit__(self, a: type[BaseException] | None, b: BaseException | None, c: types.TracebackType | None) -> None: ...
76-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
76+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
7777
def remove_child_handler(self, pid: int) -> bool: ...
7878

7979
class _UnixSelectorEventLoop(BaseSelectorEventLoop): ...
@@ -92,7 +92,7 @@ if sys.platform != "win32":
9292
class _Warn(Protocol):
9393
def __call__(
9494
self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...
95-
) -> None: ...
95+
) -> object: ...
9696

9797
class MultiLoopChildWatcher(AbstractChildWatcher):
9898
def __init__(self) -> None: ...
@@ -102,7 +102,7 @@ if sys.platform != "win32":
102102
def __exit__(
103103
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
104104
) -> None: ...
105-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
105+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
106106
def remove_child_handler(self, pid: int) -> bool: ...
107107
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
108108

@@ -115,7 +115,7 @@ if sys.platform != "win32":
115115
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
116116
) -> None: ...
117117
def __del__(self, _warn: _Warn = ...) -> None: ...
118-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
118+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
119119
def remove_child_handler(self, pid: int) -> bool: ...
120120
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
121121

@@ -129,5 +129,5 @@ if sys.platform != "win32":
129129
def is_active(self) -> bool: ...
130130
def close(self) -> None: ...
131131
def attach_loop(self, loop: AbstractEventLoop | None) -> None: ...
132-
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
132+
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
133133
def remove_child_handler(self, pid: int) -> bool: ...

stdlib/asyncio/windows_utils.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if sys.platform == "win32":
1212
class _WarnFunction(Protocol):
1313
def __call__(
1414
self, message: str, category: type[Warning] = ..., stacklevel: int = ..., source: PipeHandle = ...
15-
) -> None: ...
15+
) -> object: ...
1616
BUFSIZE: Literal[8192]
1717
PIPE = subprocess.PIPE
1818
STDOUT = subprocess.STDOUT

0 commit comments

Comments
 (0)