From 93ef68315be64d5f67c439bd385c4e2be365b631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Me=C3=9Fmer?= Date: Mon, 19 Sep 2016 17:13:12 +0200 Subject: [PATCH] Fixed types in stdlib/3/concurrent/futures: (#557) * Fixed types in stdlib/3/concurrent/futures: - Remove private classes from public interface - Add missing types * Remove "generated by stubgen" headers from modified type stubs * - Use ... as default value - Fix space formatting * Replace more default values with '...' * Use 'None' as default value where specified by documentation * Use explicit Optional[T] type instead of default value None --- stdlib/3/concurrent/futures/__init__.pyi | 4 -- stdlib/3/concurrent/futures/_base.pyi | 51 +++--------------------- stdlib/3/concurrent/futures/process.pyi | 51 +++++------------------- stdlib/3/concurrent/futures/thread.pyi | 24 ++++------- 4 files changed, 24 insertions(+), 106 deletions(-) diff --git a/stdlib/3/concurrent/futures/__init__.pyi b/stdlib/3/concurrent/futures/__init__.pyi index 91cf274ab..5b6ab81d6 100644 --- a/stdlib/3/concurrent/futures/__init__.pyi +++ b/stdlib/3/concurrent/futures/__init__.pyi @@ -1,7 +1,3 @@ -# Stubs for concurrent.futures (Python 3.5) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - from ._base import * from .thread import * from .process import * diff --git a/stdlib/3/concurrent/futures/_base.pyi b/stdlib/3/concurrent/futures/_base.pyi index 98ffaf3a6..819e79cf7 100644 --- a/stdlib/3/concurrent/futures/_base.pyi +++ b/stdlib/3/concurrent/futures/_base.pyi @@ -1,8 +1,4 @@ -# Stubs for concurrent.futures._base (Python 3.5) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - -from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple +from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional from collections import namedtuple FIRST_COMPLETED = ... # type: Any @@ -19,41 +15,6 @@ class Error(Exception): ... class CancelledError(Error): ... class TimeoutError(Error): ... -class _Waiter: - event = ... # type: Any - finished_futures = ... # type: Any - def __init__(self): ... - def add_result(self, future): ... - def add_exception(self, future): ... - def add_cancelled(self, future): ... - -class _AsCompletedWaiter(_Waiter): - lock = ... # type: Any - def __init__(self): ... - def add_result(self, future): ... - def add_exception(self, future): ... - def add_cancelled(self, future): ... - -class _FirstCompletedWaiter(_Waiter): - def add_result(self, future): ... - def add_exception(self, future): ... - def add_cancelled(self, future): ... - -class _AllCompletedWaiter(_Waiter): - num_pending_calls = ... # type: Any - stop_on_exception = ... # type: Any - lock = ... # type: Any - def __init__(self, num_pending_calls, stop_on_exception): ... - def add_result(self, future): ... - def add_exception(self, future): ... - def add_cancelled(self, future): ... - -class _AcquireFutures: - futures = ... # type: Any - def __init__(self, futures): ... - def __enter__(self): ... - def __exit__(self, *args): ... - DoneAndNotDoneFutures = namedtuple('DoneAndNotDoneFutures', 'done not_done') _T = TypeVar('_T') @@ -65,19 +26,19 @@ class Future(Generic[_T]): def running(self) -> bool: ... def done(self) -> bool: ... def add_done_callback(self, fn: Callable[[Future], Any]) -> None: ... - def result(self, timeout: float = ...) -> _T: ... - def exception(self, timeout: float = ...) -> Exception: ... + def result(self, timeout: Optional[float] = ...) -> _T: ... + def exception(self, timeout: Optional[float] = ...) -> Exception: ... def set_running_or_notify_cancel(self) -> None: ... def set_result(self, result: _T) -> None: ... def set_exception(self, exception: Exception) -> None: ... class Executor: def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ... - def map(self, func: Callable[..., _T], *iterables: Any, timeout: float = ...) -> Iterable[_T]: ... + def map(self, func: Callable[..., _T], *iterables: Any, timeout: Optional[float] = ..., chunksize: int = ...) -> Iterable[_T]: ... def shutdown(self, wait: bool = ...) -> None: ... def __enter__(self) -> Executor: ... def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ... -def as_completed(fs: Iterable[Future], timeout: float = ...) -> Iterator[Future]: ... +def as_completed(fs: Iterable[Future], timeout: Optional[float] = ...) -> Iterator[Future]: ... -def wait(fs: Iterable[Future], timeout: float = ..., return_when: str = ...) -> Tuple[Iterable[Future], Iterable[Future]]: ... +def wait(fs: Iterable[Future], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Iterable[Future], Iterable[Future]]: ... diff --git a/stdlib/3/concurrent/futures/process.pyi b/stdlib/3/concurrent/futures/process.pyi index 9bc56fabe..d3da98238 100644 --- a/stdlib/3/concurrent/futures/process.pyi +++ b/stdlib/3/concurrent/futures/process.pyi @@ -1,46 +1,15 @@ -# Stubs for concurrent.futures.process (Python 3.5) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - -from typing import Any -from . import _base +from typing import Any, Callable, TypeVar, Iterable, Optional +from ._base import Future, Executor EXTRA_QUEUED_CALLS = ... # type: Any -class _RemoteTraceback(Exception): - tb = ... # type: Any - def __init__(self, tb): ... - -class _ExceptionWithTraceback: - exc = ... # type: Any - tb = ... # type: Any - def __init__(self, exc, tb): ... - def __reduce__(self): ... - -class _WorkItem: - future = ... # type: Any - fn = ... # type: Any - args = ... # type: Any - kwargs = ... # type: Any - def __init__(self, future, fn, args, kwargs): ... - -class _ResultItem: - work_id = ... # type: Any - exception = ... # type: Any - result = ... # type: Any - def __init__(self, work_id, exception=None, result=None): ... - -class _CallItem: - work_id = ... # type: Any - fn = ... # type: Any - args = ... # type: Any - kwargs = ... # type: Any - def __init__(self, work_id, fn, args, kwargs): ... - class BrokenProcessPool(RuntimeError): ... -class ProcessPoolExecutor(_base.Executor): - def __init__(self, max_workers=None): ... - def submit(self, fn, *args, **kwargs): ... - def map(self, fn, *iterables, timeout=None, chunksize=1): ... - def shutdown(self, wait=True): ... +_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: ... + diff --git a/stdlib/3/concurrent/futures/thread.pyi b/stdlib/3/concurrent/futures/thread.pyi index f8242ff74..65885fd26 100644 --- a/stdlib/3/concurrent/futures/thread.pyi +++ b/stdlib/3/concurrent/futures/thread.pyi @@ -1,19 +1,11 @@ -# Stubs for concurrent.futures.thread (Python 3.5) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. +from typing import Any, TypeVar, Callable, Iterable, Optional +from ._base import Executor, Future -from typing import Any -from . import _base +_T = TypeVar('_T') -class _WorkItem: - future = ... # type: Any - fn = ... # type: Any - args = ... # type: Any - kwargs = ... # type: Any - def __init__(self, future, fn, args, kwargs): ... - def run(self): ... +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: ... -class ThreadPoolExecutor(_base.Executor): - def __init__(self, max_workers=None): ... - def submit(self, fn, *args, **kwargs): ... - def shutdown(self, wait=True): ...