8000 Make concurrent.futures stubs identical · python/typeshed@a13e3ad · GitHub
[go: up one dir, main page]

Skip to content

Commit a13e3ad

Browse files
author
Daniel Li
committed
Make concurrent.futures stubs identical
Make the Python 2 and 3 concurrent.futures stubs identical so fixes get applied to both. For example, #1305 and #2233 fixed the same problem at differnt times, as did #1078 and #1911. By making the stubs identical, we apply the fix from #1711 to Python 2. Fixes #2234.
1 parent a9366df commit a13e3ad

File tree

7 files changed

+102
-50
lines changed

7 files changed

+102
-50
lines changed

stdlib/3/concurrent/futures/_base.pyi

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple
2+
from types import TracebackType
3+
import sys
24

35
FIRST_COMPLETED = ... # type: str
46
FIRST_EXCEPTION = ... # type: str
@@ -24,14 +26,25 @@ class Future(Generic[_T]):
2426
def done(self) -> bool: ...
2527
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
2628
def result(self, timeout: Optional[float] = ...) -> _T: ...
27-
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
2829
def set_running_or_notify_cancel(self) -> bool: ...
2930
def set_result(self, result: _T) -> None: ...
30-
def set_exception(self, exception: Optional[BaseException]) -> None: ...
31+
32+
if sys.version_info >= (3,):
33+
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
34+
def set_exception(self, exception: Optional[BaseException]) -> None: ...
35+
else:
36+
def exception(self, timeout: Optional[float] = ...) -> Any: ...
37+
def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ...
38+
def set_exception(self, exception: Any) -> None: ...
39+
def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ...
40+
3141

3242
class Executor:
3343
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
34-
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ...
44+
if sys.version_info >= (3, 5):
45+
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ...
46+
else:
47+
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ...
3548
def shutdown(self, wait: bool = ...) -> None: ...
3649
def __enter__(self: _T) -> _T: ...
3750
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from typing import Optional, Any
22
from ._base import Future, Executor
3+
import sys
34

45
EXTRA_QUEUED_CALLS = ... # type: Any
56

6-
class BrokenProcessPool(RuntimeError): ...
7+
if sys.version_info >= (3,):
8+
class BrokenProcessPool(RuntimeError): ...
79

810
class ProcessPoolExecutor(Executor):
911
def __init__(self, max_workers: Optional[int] = ...) -> None: ...

tests/check_consistent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
{'stdlib/3.4/enum.pyi', 'third_party/3/enum.pyi'},
1515
{'stdlib/2/os/path.pyi', 'stdlib/3/os/path.pyi'},
1616
{'stdlib/3/unittest/mock.pyi', 'third_party/2and3/mock.pyi'},
17+
{'stdlib/3/concurrent/__init__.pyi', 'third_party/2/concurrent/__init__.pyi'},
18+
{'stdlib/3/concurrent/futures/__init__.pyi', 'third_party/2/concurrent/futures/__init__.pyi'},
19+
{'stdlib/3/concurrent/futures/_base.pyi', 'third_party/2/concurrent/futures/_base.pyi'},
20+
{'stdlib/3/concurrent/futures/thread.pyi', 'third_party/2/concurrent/futures/thread.pyi'},
21+
{'stdlib/3/concurrent/futures/process.pyi', 'third_party/2/concurrent/futures/process.pyi'},
1722
]
1823

1924
def main():
Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,3 @@
1-
# Stubs for concurrent.futures (Python 2)
2-
3-
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Optional, Set, Tuple, Union
4-
from types import TracebackType
5-
6-
_T = TypeVar('_T')
7-
8-
class Error(Exception): ...
9-
class CancelledError(Error): ...
10-
class TimeoutError(Error): ...
11-
12-
class Future(Generic[_T]):
13-
def cancel(self) -> bool: ...
14-
def cancelled(self) -> bool: ...
15-
def running(self) -> bool: ...
16-
def done(self) -> bool: ...
17-
def result(self, timeout: Optional[float] = ...) -> _T: ...
18-
def exception(self, timeout: Optional[float] = ...) -> Any: ...
19-
def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ...
20-
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
21-
22-
def set_running_or_notify_cancel(self) -> bool: ...
23-
def set_result(self, result: _T) -> None: ...
24-
def set_exception(self, exception: Any) -> None: ...
25-
def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ...
26-
27-
class Executor:
28-
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
29-
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...) -> Iterator[_T]: ...
30-
def shutdown(self, wait: bool = ...) -> None: ...
31-
def __enter__(self) -> Executor: ...
32-
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
33-
34-
class ThreadPoolExecutor(Executor):
35-
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
36-
37-
class ProcessPoolExecutor(Executor):
38-
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
39-
40-
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ...
41-
42-
FIRST_COMPLETED = ... # type: str
43-
FIRST_EXCEPTION = ... # type: str
44-
ALL_COMPLETED = ... # type: str
45-
46-
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
1+
from ._base import * # noqa: F403
2+
from .thread import * # noqa: F403
3+
from .process import * # noqa: F403
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from typing import TypeVar, Generic, Any, Iterable, Iterator, Callable, Tuple, Optional, Set, NamedTuple
2+
from types import TracebackType
3+
import sys
4+
5+
FIRST_COMPLETED = ... # type: str
6+
FIRST_EXCEPTION = ... # type: str
7+
ALL_COMPLETED = ... # type: str
8+
PENDING = ... # type: Any
9+
RUNNING = ... # type: Any
10+
CANCELLED = ... # type: Any
11+
CANCELLED_AND_NOTIFIED = ... # type: Any
12+
FINISHED = ... # type: Any
13+
LOGGER = ... # type: Any
14+
15+
class Error(Exception): ...
16+
class CancelledError(Error): ...
17+
class TimeoutError(Error): ...
18+
19+
_T = TypeVar('_T')
20+
21+
class Future(Generic[_T]):
22+
def __init__(self) -> None: ...
23+
def cancel(self) -> bool: ...
24+
def cancelled(self) -> bool: ...
25+
def running(self) -> bool: ...
26+
def done(self) -> bool: ...
27+
def add_done_callback(self, fn: Callable[[Future[_T]], Any]) -> None: ...
28+
def result(self, timeout: Optional[float] = ...) -> _T: ...
29+
def set_running_or_notify_cancel(self) -> bool: ...
30+
def set_result(self, result: _T) -> None: ...
31+
32+
if sys.version_info >= (3,):
33+
def exception(self, timeout: Optional[float] = ...) -> Optional[BaseException]: ...
34+
def set_exception(self, exception: Optional[BaseException]) -> None: ...
35+
else:
36+
def exception(self, timeout: Optional[float] = ...) -> Any: ...
37+
def exception_info(self, timeout: Optional[float] = ...) -> Tuple[Any, Optional[TracebackType]]: ...
38+
def set_exception(self, exception: Any) -> None: ...
39+
def set_exception_info(self, exception: Any, traceback: Optional[TracebackType]) -> None: ...
40+
41+
42+
class Executor:
43+
def submit(self, fn: Callable[..., _T], *args: Any, **kwargs: Any) -> Future[_T]: ...
44+
if sys.version_info >= (3, 5):
45+
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ..., chunksize: int = ...) -> Iterator[_T]: ...
46+
else:
47+
def map(self, func: Callable[..., _T], *iterables: Iterable[Any], timeout: Optional[float] = ...,) -> Iterator[_T]: ...
48+
def shutdown(self, wait: bool = ...) -> None: ...
49+
def __enter__(self: _T) -> _T: ...
50+
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> bool: ...
51+
52+
def as_completed(fs: Iterable[Future[_T]], timeout: Optional[float] = ...) -> Iterator[Future[_T]]: ...
53+
54+
def wait(fs: Iterable[Future[_T]], timeout: Optional[float] = ..., return_when: str = ...) -> Tuple[Set[Future[_T]], Set[Future[_T]]]: ...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import Optional, Any
2+
from ._base import Future, Executor
3+
import sys
4+
5+
EXTRA_QUEUED_CALLS = ... # type: Any
6+
7+
if sys.version_info >= (3,):
8+
class BrokenProcessPool(RuntimeError): ...
9+
10+
class ProcessPoolExecutor(Executor):
11+
def __init__(self, max_workers: Optional[int] = ...) -> None: ...
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Optional
2+
from ._base import Executor, Future
3+
import sys
4+
5+
class ThreadPoolExecutor(Executor):
6+
if sys.version_info >= (3, 6):
7+
def __init__(self, max_workers: Optional[int] = ...,
8+
thread_name_prefix: str = ...) -> None: ...
9+
else:
10+
def __init__(self, max_workers: Optional[int] = ...) -> None: ...

0 commit comments

Comments
 (0)
0