Skip to content

Commit 50f1988

Browse files
gantsevdenissrittau
authored andcommitted
concurrent: add private classes and exceptions (#3169)
1 parent 29771aa commit 50f1988

File tree

4 files changed

+138
-18
lines changed

4 files changed

+138
-18
lines changed

stdlib/3/concurrent/futures/_base.pyi

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set
1+
import threading
2+
from logging import Logger
3+
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List
24
from types import TracebackType
35
import sys
46

57
FIRST_COMPLETED: str
68
FIRST_EXCEPTION: str
79
ALL_COMPLETED: str
8-
PENDING: Any
9-
RUNNING: Any
10-
CANCELLED: Any
11-
CANCELLED_AND_NOTIFIED: Any
12-
FINISHED: Any
13-
LOGGER: Any
10+
PENDING: str
11+
RUNNING: str
12+
CANCELLED: str
13+
CANCELLED_AND_NOTIFIED: str
14+
FINISHED: str
15+
LOGGER: Logger
1416

1517
class Error(Exception): ...
1618
class CancelledError(Error): ...
1719
class TimeoutError(Error): ...
1820

21+
if sys.version_info >= (3, 7):
22+
class BrokenExecutor(RuntimeError): ...
23+
1924
_T = TypeVar('_T')
2025

2126
class Future(Generic[_T]):
@@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It
5459

5560
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]],
5661
Set[Future[_T]]]: ...
62+
63+
class _Waiter:
64+
event: threading.Event
65+
finished_futures: List[Future]
66+
def __init__(self) -> None: ...
67+
def add_result(self, future: Future) -> None: ...
68+
def add_exception(self, future: Future) -> None: ...
69+
def add_cancelled(self, future: Future) -> None: ...
70+
71+
72+
class _AsCompletedWaiter(_Waiter):
73+
lock: threading.Lock
74+
def __init__(self) -> None: ...
75+
def add_result(self, future: Future) -> None: ...
76+
def add_exception(self, future: Future) -> None: ...
77+
def add_cancelled(self, future: Future) -> None: ...
78+
79+
80+
class _FirstCompletedWaiter(_Waiter):
81+
def add_result(self, future: Future) -> None: ...
82+
def add_exception(self, future: Future) -> None: ...
83+
def add_cancelled(self, future: Future) -> None: ...
84+
85+
86+
class _AllCompletedWaiter(_Waiter):
87+
num_pending_calls: int
88+
stop_on_exception: bool
89+
lock: threading.Lock
90+
def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ...
91+
def add_result(self, future: Future) -> None: ...
92+
def add_exception(self, future: Future) -> None: ...
93+
def add_cancelled(self, future: Future) -> None: ...
94+
95+
96+
class _AcquireFutures:
97+
futures: Iterable[Future]
98+
def __init__(self, futures: Iterable[Future]) -> None: ...
99+
def __enter__(self) -> None: ...
100+
def __exit__(self, *args: Any) -> None: ...

stdlib/3/concurrent/futures/thread.pyi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
from typing import Any, Callable, Optional, Tuple
2-
from ._base import Executor
1+
from typing import Any, Callable, Optional, Tuple, TypeVar, Generic
2+
from ._base import Executor, Future
33
import sys
44

5+
if sys.version_info >= (3, 7):
6+
from ._base import BrokenExecutor
7+
class BrokenThreadPool(BrokenExecutor): ...
8+
9+
_S = TypeVar('_S')
10+
511
class ThreadPoolExecutor(Executor):
612
if sys.version_info >= (3, 7):
713
def __init__(self, max_workers: Optional[int] = ...,
@@ -13,3 +19,13 @@ class ThreadPoolExecutor(Executor):
1319
thread_name_prefix: str = ...) -> None: ...
1420
else:
1521
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
22+
23+
24+
class _WorkItem(Generic[_S]):
25+
future: Future
26+
fn: Callable[[Future[_S]], Any]
27+
args: Any
28+
kwargs: Any
29+
def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any,
30+
kwargs: Any) -> None: ...
31+
def run(self) -> None: ...

third_party/2/concurrent/futures/_base.pyi

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
1-
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set
1+
import threading
2+
from logging import Logger
3+
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, List
24
from types import TracebackType
35
import sys
46

57
FIRST_COMPLETED: str
68
FIRST_EXCEPTION: str
79
ALL_COMPLETED: str
8-
PENDING: Any
9-
RUNNING: Any
10-
CANCELLED: Any
11-
CANCELLED_AND_NOTIFIED: Any
12-
FINISHED: Any
13-
LOGGER: Any
10+
PENDING: str
11+
RUNNING: str
12+
CANCELLED: str
13+
CANCELLED_AND_NOTIFIED: str
14+
FINISHED: str
15+
LOGGER: Logger
1416

1517
class Error(Exception): ...
1618
class CancelledError(Error): ...
1719
class TimeoutError(Error): ...
1820

21+
if sys.version_info >= (3, 7):
22+
class BrokenExecutor(RuntimeError): ...
23+
1924
_T = TypeVar('_T')
2025

2126
class Future(Generic[_T]):
@@ -54,3 +59,42 @@ def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> It
5459

5560
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]],
5661
Set[Future[_T]]]: ...
62+
63+
class _Waiter:
64+
event: threading.Event
65+
finished_futures: List[Future]
66+
def __init__(self) -> None: ...
67+
def add_result(self, future: Future) -> None: ...
68+
def add_exception(self, future: Future) -> None: ...
69+
def add_cancelled(self, future: Future) -> None: ...
70+
71+
72+
class _AsCompletedWaiter(_Waiter):
73+
lock: threading.Lock
74+
def __init__(self) -> None: ...
75+
def add_result(self, future: Future) -> None: ...
76+
def add_exception(self, future: Future) -> None: ...
77+
def add_cancelled(self, future: Future) -> None: ...
78+
79+
80+
class _FirstCompletedWaiter(_Waiter):
81+
def add_result(self, future: Future) -> None: ...
82+
def add_exception(self, future: Future) -> None: ...
83+
def add_cancelled(self, future: Future) -> None: ...
84+
85+
86+
class _AllCompletedWaiter(_Waiter):
87+
num_pending_calls: int
88+
stop_on_exception: bool
89+
lock: threading.Lock
90+
def __init__(self, num_pending_calls: int, stop_on_exception: bool) -> None: ...
91+
def add_result(self, future: Future) -> None: ...
92+
def add_exception(self, future: Future) -> None: ...
93+
def add_cancelled(self, future: Future) -> None: ...
94+
95+
96+
class _AcquireFutures:
97+
futures: Iterable[Future]
98+
def __init__(self, futures: Iterable[Future]) -> None: ...
99+
def __enter__(self) -> None: ...
100+
def __exit__(self, *args: Any) -> None: ...

third_party/2/concurrent/futures/thread.pyi

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
from typing import Any, Callable, Optional, Tuple
2-
from ._base import Executor
1+
from typing import Any, Callable, Optional, Tuple, TypeVar, Generic
2+
from ._base import Executor, Future
33
import sys
44

5+
if sys.version_info >= (3, 7):
6+
from ._base import BrokenExecutor
7+
class BrokenThreadPool(BrokenExecutor): ...
8+
9+
_S = TypeVar('_S')
10+
511
class ThreadPoolExecutor(Executor):
612
if sys.version_info >= (3, 7):
713
def __init__(self, max_workers: Optional[int] = ...,
@@ -13,3 +19,13 @@ class ThreadPoolExecutor(Executor):
1319
thread_name_prefix: str = ...) -> None: ...
1420
else:
1521
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
22+
23+
24+
class _WorkItem(Generic[_S]):
25+
future: Future
26+
fn: Callable[[Future[_S]], Any]
27+
args: Any
28+
kwargs: Any
29+
def __init__(self, future: Future, fn: Callable[[Future[_S]], Any], args: Any,
30+
kwargs: Any) -> None: ...
31+
def run(self) -> None: ...

0 commit comments

Comments
 (0)