1
- # Stubs for multiprocessing.pool
2
-
3
- # NOTE: These are incomplete!
4
-
5
1
from typing import (
6
- Any , Callable , ContextManager , Iterable , Mapping , Optional , Dict , List ,
7
- TypeVar ,
2
+ Any , Callable , ContextManager , Iterable , Mapping , Optional , List ,
3
+ TypeVar , Generic ,
8
4
)
9
5
10
- _T = TypeVar ('_T' , bound = 'Pool' )
6
+ _PT = TypeVar ('_PT' , bound = 'Pool' )
7
+ _S = TypeVar ('_S' )
8
+ _T = TypeVar ('_T' )
11
9
12
- class AsyncResult ():
13
- def get (self , timeout : Optional [float ] = ...) -> Any : ...
10
+ class AsyncResult (Generic [ _T ] ):
11
+ def get (self , timeout : Optional [float ] = ...) -> _T : ...
14
12
def wait (self , timeout : Optional [float ] = ...) -> None : ...
15
13
def ready (self ) -> bool : ...
16
14
def successful (self ) -> bool : ...
17
15
18
16
_IMIT = TypeVar ('_IMIT' , bound = IMapIterator )
19
17
20
- class IMapIterator (Iterable [Any ]):
18
+ class IMapIterator (Iterable [_T ]):
21
19
def __iter__ (self : _IMIT ) -> _IMIT : ...
22
- def next (self , timeout : Optional [float ] = ...) -> Any : ...
23
- def __next__ (self , timeout : Optional [float ] = ...) -> Any : ...
20
+ def next (self , timeout : Optional [float ] = ...) -> _T : ...
21
+ def __next__ (self , timeout : Optional [float ] = ...) -> _T : ...
24
22
25
23
class Pool (ContextManager [Pool ]):
26
24
def __init__ (self , processes : Optional [int ] = ...,
@@ -29,46 +27,46 @@ class Pool(ContextManager[Pool]):
29
27
maxtasksperchild : Optional [int ] = ...,
30
28
context : Optional [Any ] = ...) -> None : ...
31
29
def apply (self ,
32
- func : Callable [..., Any ],
30
+ func : Callable [..., _T ],
33
31
args : Iterable [Any ] = ...,
34
- kwds : Dict [str , Any ] = ...) -> Any : ...
32
+ kwds : Mapping [str , Any ] = ...) -> _T : ...
35
33
def apply_async (self ,
36
- func : Callable [..., Any ],
34
+ func : Callable [..., _T ],
37
35
args : Iterable [Any ] = ...,
38
- kwds : Dict [str , Any ] = ...,
39
- callback : Optional [Callable [... , None ]] = ...,
40
- error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult : ...
36
+ kwds : Mapping [str , Any ] = ...,
37
+ callback : Optional [Callable [[ _T ] , None ]] = ...,
38
+ error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult [ _T ] : ...
41
39
def map (self ,
42
- func : Callable [..., Any ],
43
- iterable : Iterable [Any ] = ...,
44
- chunksize : Optional [int ] = ...) -> List [Any ]: ...
45
- def map_async (self , func : Callable [..., Any ],
46
- iterable : Iterable [Any ] = ...,
40
+ func : Callable [[ _S ], _T ],
41
+ iterable : Iterable [_S ] = ...,
42
+ chunksize : Optional [int ] = ...) -> List [_T ]: ...
43
+ def map_async (self , func : Callable [[ _S ], _T ],
44
+ iterable : Iterable [_S ] = ...,
47
45
chunksize : Optional [int ] = ...,
48
- callback : Optional [Callable [... , None ]] = ...,
49
- error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult : ...
46
+ callback : Optional [Callable [[ _T ] , None ]] = ...,
47
+ error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult [ List [ _T ]] : ...
50
48
def imap (self ,
51
- func : Callable [..., Any ],
52
- iterable : Iterable [Any ] = ...,
53
- chunksize : Optional [int ] = ...) -> IMapIterator : ...
49
+ func : Callable [[ _S ], _T ],
50
+ iterable : Iterable [_S ] = ...,
51
+ chunksize : Optional [int ] = ...) -> IMapIterator [ _T ] : ...
54
52
def imap_unordered (self ,
55
- func : Callable [..., Any ],
56
- iterable : Iterable [Any ] = ...,
57
- chunksize : Optional [int ] = ...) -> IMapIterator : ...
53
+ func : Callable [[ _S ], _T ],
54
+ iterable : Iterable [_S ] = ...,
55
+ chunksize : Optional [int ] = ...) -> IMapIterator [ _T ] : ...
58
56
def starmap (self ,
59
- func : Callable [..., Any ],
57
+ func : Callable [..., _T ],
60
58
iterable : Iterable [Iterable [Any ]] = ...,
61
- chunksize : Optional [int ] = ...) -> List [Any ]: ...
59
+ chunksize : Optional [int ] = ...) -> List [_T ]: ...
62
60
def starmap_async (self ,
63
- func : Callable [..., Any ],
61
+ func : Callable [..., _T ],
64
62
iterable : Iterable [Iterable [Any ]] = ...,
65
63
chunksize : Optional [int ] = ...,
66
- callback : Optional [Callable [... , None ]] = ...,
67
- error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult : ...
64
+ callback : Optional [Callable [[ _T ] , None ]] = ...,
65
+ error_callback : Optional [Callable [[BaseException ], None ]] = ...) -> AsyncResult [ List [ _T ]] : ...
68
66
def close (self ) -> None : ...
69
67
def terminate (self ) -> None : ...
70
68
def join (self ) -> None : ...
71
- def __enter__ (self : _T ) -> _T : ...
69
+ def __enter__ (self : _PT ) -> _PT : ...
72
70
73
71
74
72
class ThreadPool (Pool , ContextManager [ThreadPool ]):
0 commit comments