More precise signatures in concurrent.futures (#1262)

* Allow None in concurrent.futures.exception() and set_exception()

* Make Executor.map() signature more precise

* Remove superfluous signatures

* Specify str type for some concurrent.futures constants

* Update concurrent.futures backport

* CR fixes
This commit is contained in:
Max
2017-05-14 13:55:27 -07:00
committed by Jelle Zijlstra
parent 6207eb8cde
commit df9df65882
4 changed files with 11 additions and 21 deletions

View File

@@ -1,9 +1,9 @@
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set
from collections import namedtuple
FIRST_COMPLETED = ... # type: Any
FIRST_EXCEPTION = ... # type: Any
ALL_COMPLETED = ... # type: Any
FIRST_COMPLETED = ... # type: str
FIRST_EXCEPTION = ... # type: str
ALL_COMPLETED = ... # type: str
PENDING = ... # type: Any
RUNNING = ... # type: Any
CANCELLED = ... # type: Any
@@ -27,14 +27,14 @@ class Future(Generic[_T]):
def done(self) -> bool: ...
def add_done_callback(self, fn: Callable[[Future], Any]) -> None: ...
def result(self, timeout: Optional[float] = ...) -> _T: ...
def exception(self, timeout: Optional[float] = ...) -> BaseException: ...
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
def set_running_or_notify_cancel(self) -> None: ...
def set_result(self, result: _T) -> None: ...
def set_exception(self, exception: BaseException) -> None: ...
def set_exception(self, exception: Optional[BaseException]) -> None: ...
class Executor:
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Any, timeout: Optional[float] = ..., chunksize: int = ...) -> Iterable[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ...
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self) -> Executor: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...

View File

@@ -1,14 +1,9 @@
from typing import Any, Callable, TypeVar, Iterable, Optional
from typing import Optional, Any
from ._base import Future, Executor
EXTRA_QUEUED_CALLS = ... # type: Any
class BrokenProcessPool(RuntimeError): ...
_T = TypeVar('_T')
class ProcessPoolExecutor(Executor):
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Any, timeout: Optional[float] = ..., chunksize: int = ...) -> Iterable[_T]: ...
def shutdown(self, wait: bool = ...) -> None: ...

View File

@@ -1,10 +1,5 @@
from typing import Any, TypeVar, Callable, Iterable, Optional
from typing import Optional
from ._base import Executor, Future
_T = TypeVar('_T')
class ThreadPoolExecutor(Executor):
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Any, timeout: Optional[float] = ..., chunksize: int = ...) -> Iterable[_T]: ...
def shutdown(self, wait: bool = ...) -> None: ...

View File

@@ -26,16 +26,16 @@ class Future(Generic[_T]):
class Executor:
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Any, timeout: Optional[float] = ...) -> Iterable[_T]: ...
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...) -> Iterator[_T]: ...
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self) -> Executor: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
class ThreadPoolExecutor(Executor):
def __init__(self, max_workers: int) -> None: ...
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
class ProcessPoolExecutor(Executor):
def __init__(self, max_workers: Union[int, None] = ...) -> None: ...
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
def wait(fs: Iterable[Future], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future], Set[Future]]: ...