massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stdlib / concurrent / futures / _base.pyi
1 import sys
2 import threading
3 from _typeshed import Self
4 from abc import abstractmethod
5 from collections.abc import Container, Iterable, Iterator, Sequence
6 from logging import Logger
7 from typing import Any, Callable, Generic, Protocol, Set, TypeVar, overload
8
9 if sys.version_info >= (3, 9):
10     from types import GenericAlias
11
12 FIRST_COMPLETED: str
13 FIRST_EXCEPTION: str
14 ALL_COMPLETED: str
15 PENDING: str
16 RUNNING: str
17 CANCELLED: str
18 CANCELLED_AND_NOTIFIED: str
19 FINISHED: str
20 _FUTURE_STATES: list[str]
21 _STATE_TO_DESCRIPTION_MAP: dict[str, str]
22 LOGGER: Logger
23
24 class Error(Exception): ...
25 class CancelledError(Error): ...
26 class TimeoutError(Error): ...
27
28 if sys.version_info >= (3, 8):
29     class InvalidStateError(Error): ...
30
31 if sys.version_info >= (3, 7):
32     class BrokenExecutor(RuntimeError): ...
33
34 _T = TypeVar("_T")
35
36 _T_co = TypeVar("_T_co", covariant=True)
37
38 # Copied over Collection implementation as it does not exist in Python 2 and <3.6.
39 # Also to solve pytype issues with _Collection.
40 class _Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
41     # Implement Sized (but don't have it as a base class).
42     @abstractmethod
43     def __len__(self) -> int: ...
44
45 class Future(Generic[_T]):
46     def __init__(self) -> None: ...
47     def cancel(self) -> bool: ...
48     def cancelled(self) -> bool: ...
49     def running(self) -> bool: ...
50     def done(self) -> bool: ...
51     def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
52     def result(self, timeout: float | None = ...) -> _T: ...
53     def set_running_or_notify_cancel(self) -> bool: ...
54     def set_result(self, result: _T) -> None: ...
55     def exception(self, timeout: float | None = ...) -> BaseException | None: ...
56     def set_exception(self, exception: BaseException | None) -> None: ...
57     if sys.version_info >= (3, 9):
58         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
59
60 class Executor:
61     if sys.version_info >= (3, 9):
62         def submit(self, __fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
63     else:
64         def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
65     def map(
66         self, fn: Callable[..., _T], *iterables: Iterable[Any], timeout: float | None = ..., chunksize: int = ...
67     ) -> Iterator[_T]: ...
68     if sys.version_info >= (3, 9):
69         def shutdown(self, wait: bool = ..., *, cancel_futures: bool = ...) -> None: ...
70     else:
71         def shutdown(self, wait: bool = ...) -> None: ...
72     def __enter__(self: Self) -> Self: ...
73     def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool | None: ...
74
75 def as_completed(fs: Iterable[Future[_T]], timeout: float | None = ...) -> Iterator[Future[_T]]: ...
76
77 # Ideally this would be a namedtuple, but mypy doesn't support generic tuple types. See #1976
78 class DoneAndNotDoneFutures(Sequence[Set[Future[_T]]]):
79     done: set[Future[_T]]
80     not_done: set[Future[_T]]
81     def __new__(_cls, done: set[Future[_T]], not_done: set[Future[_T]]) -> DoneAndNotDoneFutures[_T]: ...
82     def __len__(self) -> int: ...
83     @overload
84     def __getitem__(self, i: int) -> set[Future[_T]]: ...
85     @overload
86     def __getitem__(self, s: slice) -> DoneAndNotDoneFutures[_T]: ...
87
88 def wait(fs: Iterable[Future[_T]], timeout: float | None = ..., return_when: str = ...) -> DoneAndNotDoneFutures[_T]: ...
89
90 class _Waiter:
91     event: threading.Event
92     finished_futures: list[Future[Any]]
93     def __init__(self) -> None: ...
94     def add_result(self, future: Future[Any]) -> None: ...
95     def add_exception(self, future: Future[Any]) -> None: ...
96     def add_cancelled(self, future: Future[Any]) -> None: ...
97
98 class _AsCompletedWaiter(_Waiter):
99     lock: threading.Lock
100     def __init__(self) -> None: ...
101     def add_result(self, future: Future[Any]) -> None: ...
102     def add_exception(self, future: Future[Any]) -> None: ...
103     def add_cancelled(self, future: Future[Any]) -> None: ...
104
105 class _FirstCompletedWaiter(_Waiter):
106     def add_result(self, future: Future[Any]) -> None: ...
107     def add_exception(self, future: Future[Any]) -> None: ...
108     def add_cancelled(self, future: Future[Any]) -> None: ...
109
110 class _AllCompletedWaiter(_Waiter):
111     num_pending_calls: int
112     stop_on_exception: bool
113     lock: threading.Lock
114     def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ...
115     def add_result(self, future: Future[Any]) -> None: ...
116     def add_exception(self, future: Future[Any]) -> None: ...
117     def add_cancelled(self, future: Future[Any]) -> None: ...
118
119 class _AcquireFutures:
120     futures: Iterable[Future[Any]]
121     def __init__(self, futures: Iterable[Future[Any]]) -> None: ...
122     def __enter__(self) -> None: ...
123     def __exit__(self, *args: Any) -> None: ...