Skip to content

Commit 18ae67d

Browse files
ambvJelleZijlstra
authored andcommitted
[stdlib/3/multiprocessing] Add queues.pyi, make the other stubs use it (#1879)
1 parent e7b567c commit 18ae67d

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

stdlib/3/multiprocessing/__init__.pyi

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import (
44
Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List,
5-
Union, TypeVar, Sequence, Tuple
5+
Union, Sequence, Tuple
66
)
77

88
from logging import Logger
@@ -12,11 +12,9 @@ from multiprocessing.context import (
1212
ProcessError, BufferTooShort, TimeoutError, AuthenticationError)
1313
from multiprocessing.managers import SyncManager
1414
from multiprocessing.process import current_process as current_process
15-
import queue
15+
from multiprocessing.queues import Queue, SimpleQueue, JoinableQueue
1616
import sys
1717

18-
_T = TypeVar('_T')
19-
2018
# N.B. The functions below are generated at runtime by partially applying
2119
# multiprocessing.context.BaseContext's methods, so the two signatures should
2220
# be identical (modulo self).
@@ -62,19 +60,6 @@ class Process():
6260
def is_alive(self) -> bool: ...
6361
def join(self, timeout: Optional[float] = ...) -> None: ...
6462

65-
class Queue(queue.Queue[_T]):
66-
def __init__(self, maxsize: int = ...) -> None: ...
67-
def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ...
68-
def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ...
69-
def qsize(self) -> int: ...
70-
def empty(self) -> bool: ...
71-
def full(self) -> bool: ...
72-
def put_nowait(self, item: _T) -> None: ...
73-
def get_nowait(self) -> _T: ...
74-
def close(self) -> None: ...
75-
def join_thread(self) -> None: ...
76-
def cancel_join_thread(self) -> None: ...
77-
7863
class Value():
7964
value: Any = ...
8065
def __init__(self, typecode_or_type: str, *args: Any, lock: bool = ...) -> None: ...

stdlib/3/multiprocessing/context.pyi

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from logging import Logger
44
import multiprocessing
55
from multiprocessing import synchronize
6+
from multiprocessing import queues
67
import sys
78
from typing import (
89
Any, Callable, Iterable, Optional, List, Mapping, Sequence, Tuple, Type,
@@ -51,12 +52,9 @@ class BaseContext(object):
5152
def RLock(self) -> synchronize.RLock: ...
5253
def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ...
5354

54-
# TODO: change return to Queue once a stub exists in multiprocessing.queues
55-
def Queue(self, maxsize: int = ...) -> Any: ...
56-
# TODO: change return to Queue once a stub exists in multiprocessing.queues
57-
def JoinableQueue(self, maxsize: int = ...) -> Any: ...
58-
# TODO: change return to SimpleQueue once a stub exists in multiprocessing.queues
59-
def SimpleQueue(self) -> Any: ...
55+
def Queue(self, maxsize: int = ...) -> queues.Queue: ...
56+
def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue: ...
57+
def SimpleQueue(self) -> queues.SimpleQueue: ...
6058
def Pool(
6159
self,
6260
processes: Optional[int] = ...,

stdlib/3/multiprocessing/queues.pyi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from typing import Any, Generic, Optional, TypeVar
2+
3+
import queue
4+
5+
_T = TypeVar('_T')
6+
7+
class Queue(queue.Queue[_T]):
8+
# FIXME: `ctx` is a circular dependency and it's not actually optional.
9+
# It's marked as such to be able to use the generic Queue in __init__.pyi.
10+
def __init__(self, maxsize: int = ..., *, ctx: Any = ...) -> None: ...
11+
def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ...
12+
def put(self, obj: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ...
13+
def qsize(self) -> int: ...
14+
def empty(self) -> bool: ...
15+
def full(self) -> bool: ...
16+
def put_nowait(self, item: _T) -> None: ...
17+
def get_nowait(self) -> _T: ...
18+
def close(self) -> None: ...
19+
def join_thread(self) -> None: ...
20+
def cancel_join_thread(self) -> None: ...
21+
22+
class JoinableQueue(Queue[_T]):
23+
def task_done(self) -> None: ...
24+
def join(self) -> None: ...
25+
26+
class SimpleQueue(Generic[_T]):
27+
def __init__(self, *, ctx: Any = ...) -> None: ...
28+
def empty(self) -> bool: ...
29+
def get(self) -> _T: ...
30+
def put(self, item: _T) -> None: ...

0 commit comments

Comments
 (0)