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

[multiprocessing] fixes some stubtest cases for Value and Array #4282

Merged
merged 6 commits into from
Jun 27, 2020
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
40 changes: 15 additions & 25 deletions stdlib/3/multiprocessing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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).
Expand All @@ -50,30 +49,21 @@ def Pool(processes: Optional[int] = ...,
initargs: Iterable[Any] = ...,
maxtasksperchild: Optional[int] = ...) -> pool.Pool: ...

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: ...

# 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: ...

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: ...
Expand Down
7 changes: 3 additions & 4 deletions stdlib/3/multiprocessing/context.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: ...
Expand Down
42 changes: 42 additions & 0 deletions stdlib/3/multiprocessing/sharedctypes.pyi
Original file line number Diff line number Diff line change
@@ -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: ...