Skip to content

Commit

Permalink
Multiprocessing fixes (#687)
Browse files Browse the repository at this point in the history
* Fix type declarations for multiprocessing.pool.ThreadPool

The existing incomplete type declarations were replaced by a copy of
multiprocessing.Pool's declarations, suitably modified.

Fixes #683.

* Change iterable type to Iterable[Iterable[Any]] in starmap

multiprocessing.Pool and multiprocessing.pool.ThreadPool have starmap
and related methods, where the iterable argument is expected to yield
iterables. The type declarations now reflect this.
  • Loading branch information
DarwinAwardWinner authored and gvanrossum committed Nov 13, 2016
1 parent 88350e7 commit f36d7a3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
4 changes: 2 additions & 2 deletions stdlib/3/multiprocessing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class Pool():
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def starmap(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
iterable: Iterable[Iterable[Any]]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def starmap_async(self,
func: Callable[..., Any],
iterable: Iterable[Any] = (),
iterable: Iterable[Iterable[Any]] = (),
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
Expand Down
58 changes: 40 additions & 18 deletions stdlib/3/multiprocessing/pool.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# NOTE: These are incomplete!

from typing import Any, Callable, Iterable, List, Sequence
from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List

class AsyncResult():
def get(self, timeout: float = -1) -> Any: ...
Expand All @@ -11,26 +11,48 @@ class AsyncResult():
def successful(self) -> bool: ...

class ThreadPool():
def __init__(self, processes: int = ...) -> None: ...
def apply_async(self, func: Callable[..., Any],
args: Sequence[Any]=(),
kwds: Dict[str, Any]={},
callback: Callable[..., None] = None) -> AsyncResult: ...
def apply(self, func: Callable[..., Any],
args: Sequence[Any]=(),
def __init__(self, processes: Optional[int] = None,
initializer: Optional[Callable[..., None]] = None,
initargs: Iterable[Any] = ()) -> None: ...
def apply(self,
func: Callable[..., Any],
args: Iterable[Any]=(),
kwds: Dict[str, Any]={}) -> Any: ...
def map(self, func: Callable[..., Any],
iterable: Iterable[Any]=()) -> List[Any]: ...
def apply_async(self,
func: Callable[..., Any],
args: Iterable[Any]=(),
kwds: Dict[str, Any]={},
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def map(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def map_async(self, func: Callable[..., Any],
iterable: Iterable[Any] = (),
chunksize: int = -1,
callback: Callable[..., None] = None) -> AsyncResult: ...
def imap(self, func: Callable[..., Any],
iterable: Iterable[Any]=()) -> Iterable[Any]: ...
def imap_async(self, func: Callable[..., Any],
chunksize: int = -1,
iterable: Iterable[Any]=(),
callback: Callable[..., None] = None) -> AsyncResult: ...
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def imap(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def imap_unordered(self,
func: Callable[..., Any],
iterable: Iterable[Any]=(),
chunksize: Optional[int] = None) -> Iterable[Any]: ...
def starmap(self,
func: Callable[..., Any],
iterable: Iterable[Iterable[Any]]=(),
chunksize: Optional[int] = None) -> List[Any]: ...
def starmap_async(self,
func: Callable[..., Any],
iterable: Iterable[Iterable[Any]] = (),
chunksize: Optional[int] = None,
callback: Callable[..., None] = None,
error_callback: Callable[[BaseException], None] = None) -> AsyncResult: ...
def close(self) -> None: ...
def terminate(self) -> None: ...
def join(self) -> None: ...
def __enter__(self) -> 'ThreadPool': ...
def __exit__(self, exc_type, exc_val, exc_tb) -> None: ...

0 comments on commit f36d7a3

Please sign in to comment.