Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve asyncio callbacks #8192

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions stdlib/asyncio/base_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else:
_T = TypeVar("_T")
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
_Context: TypeAlias = dict[str, Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
_SSLContext: TypeAlias = bool | None | ssl.SSLContext

Expand Down Expand Up @@ -74,11 +74,11 @@ 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[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
def call_later(
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> TimerHandle: ...
def time(self) -> float: ...
# Future methods
def create_future(self) -> Future[Any]: ...
Expand All @@ -95,7 +95,7 @@ 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[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
def set_default_executor(self, executor: Any) -> None: ...
# Network I/O methods returning Futures.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/asyncio/base_subprocess.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
def terminate(self) -> None: ...
def kill(self) -> None: ...
async def _connect_pipes(self, waiter: futures.Future[Any] | None) -> None: ... # undocumented
def _call(self, cb: Callable[..., Any], *data: Any) -> None: ... # undocumented
def _call(self, cb: Callable[..., object], *data: Any) -> None: ... # undocumented
def _pipe_connection_lost(self, fd: int, exc: BaseException | None) -> None: ... # undocumented
def _pipe_data_received(self, fd: int, data: bytes) -> None: ... # undocumented
def _process_exited(self, returncode: int) -> None: ... # undocumented
Expand Down
24 changes: 12 additions & 12 deletions stdlib/asyncio/events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ else:
_T = TypeVar("_T")
_ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol)
_Context: TypeAlias = dict[str, Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any]
_ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object]
_ProtocolFactory: TypeAlias = Callable[[], BaseProtocol]
_SSLContext: TypeAlias = bool | None | ssl.SSLContext

Expand All @@ -70,7 +70,7 @@ class Handle:
_cancelled: bool
_args: Sequence[Any]
def __init__(
self, callback: Callable[..., Any], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
self, callback: Callable[..., object], args: Sequence[Any], loop: AbstractEventLoop, context: Context | None = ...
) -> None: ...
def cancel(self) -> None: ...
def _run(self) -> None: ...
Expand All @@ -80,7 +80,7 @@ class TimerHandle(Handle):
def __init__(
self,
when: float,
callback: Callable[..., Any],
callback: Callable[..., object],
args: Sequence[Any],
loop: AbstractEventLoop,
context: Context | None = ...,
Expand Down Expand Up @@ -133,22 +133,22 @@ 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[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
@abstractmethod
def call_later(
self, delay: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, delay: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
@abstractmethod
def call_at(
self, when: float, callback: Callable[..., Any], *args: Any, context: Context | None = ...
self, when: float, callback: Callable[..., object], *args: Any, context: Context | None = ...
) -> TimerHandle: ...
else:
@abstractmethod
def call_soon(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
def call_soon(self, callback: Callable[..., object], *args: Any) -> Handle: ...
@abstractmethod
def call_later(self, delay: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
def call_later(self, delay: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...
@abstractmethod
def call_at(self, when: float, callback: Callable[..., Any], *args: Any) -> TimerHandle: ...
def call_at(self, when: float, callback: Callable[..., object], *args: Any) -> TimerHandle: ...

@abstractmethod
def time(self) -> float: ...
Expand Down Expand Up @@ -181,10 +181,10 @@ 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[..., Any], *args: Any, context: Context | None = ...) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any, context: Context | None = ...) -> Handle: ...
else:
@abstractmethod
def call_soon_threadsafe(self, callback: Callable[..., Any], *args: Any) -> Handle: ...
def call_soon_threadsafe(self, callback: Callable[..., object], *args: Any) -> Handle: ...

@abstractmethod
def run_in_executor(self, executor: Any, func: Callable[..., _T], *args: Any) -> Future[_T]: ...
Expand Down Expand Up @@ -577,7 +577,7 @@ class AbstractEventLoop:
async def sock_sendto(self, sock: socket, data: bytes, address: _Address) -> None: ...
# Signal handling.
@abstractmethod
def add_signal_handler(self, sig: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_signal_handler(self, sig: int, callback: Callable[..., object], *args: Any) -> None: ...
@abstractmethod
def remove_signal_handler(self, sig: int) -> bool: ...
# Error handlers.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/futures.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Future(Awaitable[_T], Iterable[_T]):
def get_loop(self) -> AbstractEventLoop: ...
@property
def _callbacks(self: Self) -> list[tuple[Callable[[Self], Any], Context]]: ...
def add_done_callback(self: Self, __fn: Callable[[Self], Any], *, context: Context | None = ...) -> None: ...
def add_done_callback(self: Self, __fn: Callable[[Self], object], *, context: Context | None = ...) -> None: ...
if sys.version_info >= (3, 9):
def cancel(self, msg: Any | None = ...) -> bool: ...
else:
Expand All @@ -54,7 +54,7 @@ class Future(Awaitable[_T], Iterable[_T]):
def done(self) -> bool: ...
def result(self) -> _T: ...
def exception(self) -> BaseException | None: ...
def remove_done_callback(self: Self, __fn: Callable[[Self], Any]) -> int: ...
def remove_done_callback(self: Self, __fn: Callable[[Self], object]) -> int: ...
def set_result(self, __result: _T) -> None: ...
def set_exception(self, __exception: type | BaseException) -> None: ...
def __iter__(self) -> Generator[Any, None, _T]: ...
Expand Down
2 changes: 1 addition & 1 deletion stdlib/asyncio/proactor_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if sys.version_info >= (3, 8):
class _WarnCallbackProtocol(Protocol):
def __call__(
self, message: str, category: type[Warning] | None = ..., stacklevel: int = ..., source: Any | None = ...
) -> None: ...
) -> object: ...

class _ProactorBasePipeTransport(transports._FlowControlMixin, transports.BaseTransport):
def __init__(
Expand Down
4 changes: 2 additions & 2 deletions stdlib/asyncio/sslproto.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ if sys.version_info < (3, 11):
def need_ssldata(self) -> bool: ...
@property
def wrapped(self) -> bool: ...
def do_handshake(self, callback: Callable[[BaseException | None], None] | None = ...) -> list[bytes]: ...
def shutdown(self, callback: Callable[[], None] | None = ...) -> list[bytes]: ...
def do_handshake(self, callback: Callable[[BaseException | None], object] | None = ...) -> list[bytes]: ...
def shutdown(self, callback: Callable[[], object] | None = ...) -> list[bytes]: ...
def feed_eof(self) -> None: ...
def feed_ssldata(self, data: bytes, only_handshake: bool = ...) -> tuple[list[bytes], list[bytes]]: ...
def feed_appdata(self, data: bytes, offset: int = ...) -> tuple[list[bytes], int]: ...
Expand Down
14 changes: 7 additions & 7 deletions stdlib/asyncio/unix_events.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ from .selector_events import BaseSelectorEventLoop
# So, it is special cased.
class AbstractChildWatcher:
@abstractmethod
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
@abstractmethod
def remove_child_handler(self, pid: int) -> bool: ...
@abstractmethod
Expand Down Expand Up @@ -67,13 +67,13 @@ if sys.platform != "win32":
class SafeChildWatcher(BaseChildWatcher):
def __enter__(self: 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[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...

class FastChildWatcher(BaseChildWatcher):
def __enter__(self: 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[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...

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

class MultiLoopChildWatcher(AbstractChildWatcher):
def __init__(self) -> None: ...
Expand All @@ -102,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 add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> 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: ...

Expand All @@ -115,7 +115,7 @@ if sys.platform != "win32":
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: types.TracebackType | None
) -> None: ...
def __del__(self, _warn: _Warn = ...) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., Any], *args: Any) -> 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: ...

Expand All @@ -129,5 +129,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[..., Any], *args: Any) -> None: ...
def add_child_handler(self, pid: int, callback: Callable[..., object], *args: Any) -> None: ...
def remove_child_handler(self, pid: int) -> bool: ...
2 changes: 1 addition & 1 deletion stdlib/asyncio/windows_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if sys.platform == "win32":
class _WarnFunction(Protocol):
def __call__(
self, message: str, category: type[Warning] = ..., stacklevel: int = ..., source: PipeHandle = ...
) -> None: ...
) -> object: ...
BUFSIZE: Literal[8192]
PIPE = subprocess.PIPE
STDOUT = subprocess.STDOUT
Expand Down