Re-organize directory structure (#4971)

See discussion in #2491

Co-authored-by: Ivan Levkivskyi <ilevkivskyi@dropbox.com>
This commit is contained in:
Ivan Levkivskyi
2021-01-27 12:00:39 +00:00
committed by GitHub
parent 869238e587
commit 16ae4c6120
1399 changed files with 601 additions and 97 deletions

View File

View File

@@ -0,0 +1,20 @@
import sys
from ._base import (
ALL_COMPLETED as ALL_COMPLETED,
FIRST_COMPLETED as FIRST_COMPLETED,
FIRST_EXCEPTION as FIRST_EXCEPTION,
CancelledError as CancelledError,
Executor as Executor,
Future as Future,
TimeoutError as TimeoutError,
as_completed as as_completed,
wait as wait,
)
from .process import ProcessPoolExecutor as ProcessPoolExecutor
from .thread import ThreadPoolExecutor as ThreadPoolExecutor
if sys.version_info >= (3, 8):
from ._base import InvalidStateError as InvalidStateError
if sys.version_info >= (3, 7):
from ._base import BrokenExecutor as BrokenExecutor

View File

@@ -0,0 +1,133 @@
import sys
import threading
from abc import abstractmethod
from logging import Logger
from typing import (
Any,
Callable,
Container,
Generic,
Iterable,
Iterator,
List,
Optional,
Protocol,
Sequence,
Set,
TypeVar,
overload,
)
if sys.version_info >= (3, 9):
from types import GenericAlias
FIRST_COMPLETED: str
FIRST_EXCEPTION: str
ALL_COMPLETED: str
PENDING: str
RUNNING: str
CANCELLED: str
CANCELLED_AND_NOTIFIED: str
FINISHED: str
LOGGER: Logger
class Error(Exception): ...
class CancelledError(Error): ...
class TimeoutError(Error): ...
if sys.version_info >= (3, 8):
class InvalidStateError(Error): ...
if sys.version_info >= (3, 7):
class BrokenExecutor(RuntimeError): ...
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
# Copied over Collection implementation as it does not exist in Python 2 and <3.6.
# Also to solve pytype issues with _Collection.
class _Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
# Implement Sized (but don't have it as a base class).
@abstractmethod
def __len__(self) -> int: ...
class Future(Generic[_T]):
def __init__(self) -> None: ...
def cancel(self) -> bool: ...
def cancelled(self) -> bool: ...
def running(self) -> bool: ...
def done(self) -> bool: ...
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
def result(self, timeout: Optional[float] = ...) -> _T: ...
def set_running_or_notify_cancel(self) -> bool: ...
def set_result(self, result: _T) -> None: ...
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
def set_exception(self, exception: Optional[BaseException]) -> None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...
class Executor:
if sys.version_info >= (3, 9):
def submit(self, __fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
else:
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
def map(
self, fn: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...
) -> Iterator[_T]: ...
if sys.version_info >= (3, 9):
def shutdown(self, wait: bool = ..., *, cancel_futures: bool = ...) -> None: ...
else:
def shutdown(self, wait: bool = ...) -> None: ...
def __enter__(self: _T) -> _T: ...
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Optional[bool]: ...
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
# Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
class DoneAndNotDoneFutures(Sequence[Set[Future[_T]]]):
done: Set[Future[_T]]
not_done: Set[Future[_T]]
def __new__(_cls, done: Set[Future[_T]], not_done: Set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
def __len__(self) -> int: ...
@overload
def __getitem__(self, i: int) -> Set[Future[_T]]: ...
@overload
def __getitem__(self, s: slice) -> DoneAndNotDoneFutures[_T]: ...
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> DoneAndNotDoneFutures[_T]: ...
class _Waiter:
event: threading.Event
finished_futures: List[Future[Any]]
def __init__(self) -> None: ...
def add_result(self, future: Future[Any]) -> None: ...
def add_exception(self, future: Future[Any]) -> None: ...
def add_cancelled(self, future: Future[Any]) -> None: ...
class _AsCompletedWaiter(_Waiter):
lock: threading.Lock
def __init__(self) -> None: ...
def add_result(self, future: Future[Any]) -> None: ...
def add_exception(self, future: Future[Any]) -> None: ...
def add_cancelled(self, future: Future[Any]) -> None: ...
class _FirstCompletedWaiter(_Waiter):
def add_result(self, future: Future[Any]) -> None: ...
def add_exception(self, future: Future[Any]) -> None: ...
def add_cancelled(self, future: Future[Any]) -> None: ...
class _AllCompletedWaiter(_Waiter):
num_pending_calls: int
stop_on_exception: bool
lock: threading.Lock
def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ...
def add_result(self, future: Future[Any]) -> None: ...
def add_exception(self, future: Future[Any]) -> None: ...
def add_cancelled(self, future: Future[Any]) -> None: ...
class _AcquireFutures:
futures: Iterable[Future[Any]]
def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
def __enter__(self) -> None: ...
def __exit__(self, *args: Any) -> None: ...

View File

@@ -0,0 +1,28 @@
import sys
from typing import Any, Callable, Optional, Tuple
from ._base import Executor
EXTRA_QUEUED_CALLS: Any
if sys.version_info >= (3, 7):
from ._base import BrokenExecutor
class BrokenProcessPool(BrokenExecutor): ...
else:
class BrokenProcessPool(RuntimeError): ...
if sys.version_info >= (3, 7):
from multiprocessing.context import BaseContext
class ProcessPoolExecutor(Executor):
def __init__(
self,
max_workers: Optional[int] = ...,
mp_context: Optional[BaseContext] = ...,
initializer: Optional[Callable[..., None]] = ...,
initargs: Tuple[Any, ...] = ...,
) -> None: ...
else:
class ProcessPoolExecutor(Executor):
def __init__(self, max_workers: Optional[int] = ...) -> None: ...

View File

@@ -0,0 +1,42 @@
import queue
import sys
from typing import Any, Callable, Generic, Iterable, Mapping, Optional, Tuple, TypeVar
from ._base import Executor, Future
if sys.version_info >= (3, 7):
from ._base import BrokenExecutor
class BrokenThreadPool(BrokenExecutor): ...
if sys.version_info >= (3, 9):
from types import GenericAlias
_S = TypeVar("_S")
class ThreadPoolExecutor(Executor):
if sys.version_info >= (3, 7):
_work_queue: queue.SimpleQueue[Any]
else:
_work_queue: queue.Queue[Any]
if sys.version_info >= (3, 7):
def __init__(
self,
max_workers: Optional[int] = ...,
thread_name_prefix: str = ...,
initializer: Optional[Callable[..., None]] = ...,
initargs: Tuple[Any, ...] = ...,
) -> None: ...
elif sys.version_info >= (3, 6):
def __init__(self, max_workers: Optional[int] = ..., thread_name_prefix: str = ...) -> None: ...
else:
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
class _WorkItem(Generic[_S]):
future: Future[_S]
fn: Callable[..., _S]
args: Iterable[Any]
kwargs: Mapping[str, Any]
def __init__(self, future: Future[_S], fn: Callable[..., _S], args: Iterable[Any], kwargs: Mapping[str, Any]) -> None: ...
def run(self) -> None: ...
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...