mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-16 00:37:10 +08:00
Add types to multiprocessing/reduction.pyi (#9171)
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import pickle
|
||||
import sys
|
||||
from _typeshed import HasFileno, Incomplete
|
||||
from _typeshed import HasFileno, SupportsWrite
|
||||
from abc import ABCMeta
|
||||
from builtins import type as Type # alias to avoid name clash
|
||||
from collections.abc import Callable
|
||||
from copyreg import _DispatchTableType
|
||||
from multiprocessing import connection
|
||||
from pickle import _ReducedType
|
||||
from socket import socket
|
||||
from typing import Any
|
||||
from typing_extensions import Literal
|
||||
|
||||
if sys.platform == "win32":
|
||||
@@ -11,18 +16,20 @@ if sys.platform == "win32":
|
||||
else:
|
||||
__all__ = ["send_handle", "recv_handle", "ForkingPickler", "register", "dump", "DupFd", "sendfds", "recvfds"]
|
||||
|
||||
HAVE_SEND_HANDLE: bool
|
||||
|
||||
class ForkingPickler(pickle.Pickler):
|
||||
dispatch_table: _DispatchTableType
|
||||
def __init__(self, *args) -> None: ...
|
||||
def __init__(self, file: SupportsWrite[bytes], protocol: int | None = ...) -> None: ...
|
||||
@classmethod
|
||||
def register(cls, type, reduce) -> None: ...
|
||||
def register(cls, type: Type, reduce: Callable[[Any], _ReducedType]) -> None: ...
|
||||
@classmethod
|
||||
def dumps(cls, obj, protocol: Incomplete | None = ...): ...
|
||||
def dumps(cls, obj: Any, protocol: int | None = ...) -> memoryview: ...
|
||||
loads = pickle.loads
|
||||
|
||||
register = ForkingPickler.register
|
||||
|
||||
def dump(obj, file, protocol: Incomplete | None = ...) -> None: ...
|
||||
def dump(obj: Any, file: SupportsWrite[bytes], protocol: int | None = ...) -> None: ...
|
||||
|
||||
if sys.platform == "win32":
|
||||
if sys.version_info >= (3, 8):
|
||||
@@ -32,13 +39,13 @@ if sys.platform == "win32":
|
||||
else:
|
||||
def duplicate(handle: int, target_process: int | None = ..., inheritable: bool = ...) -> int: ...
|
||||
|
||||
def steal_handle(source_pid, handle): ...
|
||||
def send_handle(conn, handle, destination_pid) -> None: ...
|
||||
def recv_handle(conn): ...
|
||||
def steal_handle(source_pid: int, handle: int) -> int: ...
|
||||
def send_handle(conn: connection.PipeConnection, handle: int, destination_pid: int) -> None: ...
|
||||
def recv_handle(conn: connection.PipeConnection) -> int: ...
|
||||
|
||||
class DupHandle:
|
||||
def __init__(self, handle, access, pid: Incomplete | None = ...) -> None: ...
|
||||
def detach(self): ...
|
||||
def __init__(self, handle: int, access: int, pid: int | None = ...) -> None: ...
|
||||
def detach(self) -> int: ...
|
||||
|
||||
else:
|
||||
if sys.platform == "darwin":
|
||||
@@ -47,10 +54,11 @@ else:
|
||||
ACKNOWLEDGE: Literal[False]
|
||||
|
||||
def recvfds(sock: socket, size: int) -> list[int]: ...
|
||||
def send_handle(conn, handle, destination_pid) -> None: ...
|
||||
# destination_pid is unused
|
||||
def send_handle(conn: HasFileno, handle: int, destination_pid: object) -> None: ...
|
||||
def recv_handle(conn: HasFileno) -> int: ...
|
||||
def sendfds(sock, fds) -> None: ...
|
||||
def DupFd(fd): ...
|
||||
def sendfds(sock: socket, fds: list[int]) -> None: ...
|
||||
def DupFd(fd: int) -> Any: ... # Return type is really hard to get right
|
||||
|
||||
# These aliases are to work around pyright complaints.
|
||||
# Pyright doesn't like it when a class object is defined as an alias
|
||||
@@ -84,4 +92,5 @@ class AbstractReducer(metaclass=ABCMeta):
|
||||
sendfds = _sendfds
|
||||
recvfds = _recvfds
|
||||
DupFd = _DupFd
|
||||
def __init__(self, *args) -> None: ...
|
||||
# *args are unused
|
||||
def __init__(self, *args: object) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user