mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-15 16:27:08 +08:00
Improve asyncio callbacks (#8192)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]: ...
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: ...
|
||||
@@ -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 = ...,
|
||||
@@ -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: ...
|
||||
@@ -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]: ...
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -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__(
|
||||
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -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
|
||||
@@ -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): ...
|
||||
@@ -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: ...
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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: ...
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user