mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
multiprocessing: add sharedctypes, fix some stubtest cases (#4282)
This commit is contained in:
@@ -3,7 +3,7 @@ from typing import Any, Callable, Iterable, Optional, List, Union, Sequence, Tup
|
||||
from typing_extensions import Literal
|
||||
from ctypes import _CData
|
||||
from logging import Logger
|
||||
from multiprocessing import connection, pool, spawn, synchronize
|
||||
from multiprocessing import connection, pool, sharedctypes, spawn, synchronize
|
||||
from multiprocessing.context import (
|
||||
AuthenticationError as AuthenticationError,
|
||||
BaseContext,
|
||||
@@ -26,7 +26,6 @@ if sys.version_info >= (3, 8):
|
||||
if sys.platform != "win32":
|
||||
from multiprocessing.context import ForkContext, ForkServerContext
|
||||
|
||||
|
||||
# N.B. The functions below are generated at runtime by partially applying
|
||||
# multiprocessing.context.BaseContext's methods, so the two signatures should
|
||||
# be identical (modulo self).
|
||||
@@ -50,30 +49,21 @@ def Pool(processes: Optional[int] = ...,
|
||||
initargs: Iterable[Any] = ...,
|
||||
maxtasksperchild: Optional[int] = ...) -> pool.Pool: ...
|
||||
|
||||
class Array:
|
||||
value: Any = ...
|
||||
# Functions Array and Value are copied from context.pyi.
|
||||
# See https://github.com/python/typeshed/blob/ac234f25927634e06d9c96df98d72d54dd80dfc4/stdlib/2and3/turtle.pyi#L284-L291
|
||||
# for rationale
|
||||
def Array(
|
||||
typecode_or_type: Any,
|
||||
size_or_initializer: Union[int, Sequence[Any]],
|
||||
*,
|
||||
lock: bool = ...
|
||||
) -> sharedctypes._Array: ...
|
||||
|
||||
def __init__(self, typecode_or_type: Union[str, Type[_CData]], size_or_initializer: Union[int, Sequence[Any]], *, lock: Union[bool, _LockLike] = ...) -> None: ...
|
||||
def acquire(self) -> bool: ...
|
||||
def release(self) -> bool: ...
|
||||
def get_lock(self) -> _LockLike: ...
|
||||
def get_obj(self) -> Any: ...
|
||||
|
||||
@overload
|
||||
def __getitem__(self, key: int) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice) -> List[Any]: ...
|
||||
def __getslice__(self, start: int, stop: int) -> Any: ...
|
||||
def __setitem__(self, key: int, value: Any) -> None: ...
|
||||
|
||||
|
||||
class Value():
|
||||
value: Any = ...
|
||||
def __init__(self, typecode_or_type: Union[str, Type[_CData]], *args: Any, lock: Union[bool, _LockLike] = ...) -> None: ...
|
||||
def get_lock(self) -> _LockLike: ...
|
||||
def get_obj(self) -> Any: ...
|
||||
def acquire(self) -> bool: ...
|
||||
def release(self) -> bool: ...
|
||||
def Value(
|
||||
typecode_or_type: Any,
|
||||
*args: Any,
|
||||
lock: bool = ...
|
||||
) -> sharedctypes._Value: ...
|
||||
|
||||
# ----- multiprocessing function stubs -----
|
||||
def allow_connection_pickling() -> None: ...
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from logging import Logger
|
||||
import multiprocessing
|
||||
from multiprocessing import sharedctypes
|
||||
from multiprocessing import synchronize
|
||||
from multiprocessing import queues
|
||||
from multiprocessing.process import BaseProcess
|
||||
@@ -73,23 +74,21 @@ class BaseContext(object):
|
||||
def RawArray(self, typecode_or_type: Any, size_or_initializer: Union[int, Sequence[Any]]) -> Any: ...
|
||||
# TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out
|
||||
# how to handle the ctype
|
||||
# TODO: change return to Value once a stub exists in multiprocessing.sharedctypes
|
||||
def Value(
|
||||
self,
|
||||
typecode_or_type: Any,
|
||||
*args: Any,
|
||||
lock: bool = ...
|
||||
) -> Any: ...
|
||||
) -> sharedctypes._Value: ...
|
||||
# TODO: typecode_or_type param is a ctype with a base class of _SimpleCData or array.typecode Need to figure out
|
||||
# how to handle the ctype
|
||||
# TODO: change return to Array once a stub exists in multiprocessing.sharedctypes
|
||||
def Array(
|
||||
self,
|
||||
typecode_or_type: Any,
|
||||
size_or_initializer: Union[int, Sequence[Any]],
|
||||
*,
|
||||
lock: bool = ...
|
||||
) -> Any: ...
|
||||
) -> sharedctypes._Array: ...
|
||||
def freeze_support(self) -> None: ...
|
||||
def get_logger(self) -> Logger: ...
|
||||
def log_to_stderr(self, level: Optional[str] = ...) -> Logger: ...
|
||||
|
||||
42
stdlib/3/multiprocessing/sharedctypes.pyi
Normal file
42
stdlib/3/multiprocessing/sharedctypes.pyi
Normal file
@@ -0,0 +1,42 @@
|
||||
from ctypes import _CData
|
||||
from typing import Any, List, Optional, Sequence, Type, Union, overload
|
||||
|
||||
from multiprocessing.synchronize import _LockLike
|
||||
from multiprocessing.context import BaseContext
|
||||
|
||||
class _Array:
|
||||
value: Any = ...
|
||||
|
||||
def __init__(self, typecode_or_type: Union[str, Type[_CData]], size_or_initializer: Union[int, Sequence[Any]], *, lock: Union[bool, _LockLike] = ...) -> None: ...
|
||||
def acquire(self) -> bool: ...
|
||||
def release(self) -> bool: ...
|
||||
def get_lock(self) -> _LockLike: ...
|
||||
def get_obj(self) -> Any: ...
|
||||
|
||||
@overload
|
||||
def __getitem__(self, key: int) -> Any: ...
|
||||
@overload
|
||||
def __getitem__(self, key: slice) -> List[Any]: ...
|
||||
def __getslice__(self, start: int, stop: int) -> Any: ...
|
||||
def __setitem__(self, key: int, value: Any) -> None: ...
|
||||
|
||||
class _Value():
|
||||
value: Any = ...
|
||||
def __init__(self, typecode_or_type: Union[str, Type[_CData]], *args: Any, lock: Union[bool, _LockLike] = ...) -> None: ...
|
||||
def get_lock(self) -> _LockLike: ...
|
||||
def get_obj(self) -> Any: ...
|
||||
def acquire(self) -> bool: ...
|
||||
def release(self) -> bool: ...
|
||||
|
||||
def Array(
|
||||
typecode_or_type: Union[str, Type[_CData]],
|
||||
size_or_initializer: Union[int, Sequence[Any]],
|
||||
*,
|
||||
lock: Union[bool, _LockLike] = ...,
|
||||
ctx: Optional[BaseContext] = ...) -> _Array: ...
|
||||
|
||||
def Value(
|
||||
typecode_or_type: Union[str, Type[_CData]],
|
||||
*args: Any,
|
||||
lock: Union[bool, _LockLike] = ...,
|
||||
ctx: Optional[BaseContext] = ...) -> _Value: ...
|
||||
Reference in New Issue
Block a user