From 18ae67d04078d2a55edd78803491824057c0552a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Sat, 17 Feb 2018 01:00:44 +0000 Subject: [PATCH] [stdlib/3/multiprocessing] Add queues.pyi, make the other stubs use it (#1879) --- stdlib/3/multiprocessing/__init__.pyi | 19 ++--------------- stdlib/3/multiprocessing/context.pyi | 10 ++++----- stdlib/3/multiprocessing/queues.pyi | 30 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 stdlib/3/multiprocessing/queues.pyi diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index a8a3260ad..3e0762182 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -2,7 +2,7 @@ from typing import ( Any, Callable, ContextManager, Iterable, Mapping, Optional, Dict, List, - Union, TypeVar, Sequence, Tuple + Union, Sequence, Tuple ) from logging import Logger @@ -12,11 +12,9 @@ from multiprocessing.context import ( ProcessError, BufferTooShort, TimeoutError, AuthenticationError) from multiprocessing.managers import SyncManager from multiprocessing.process import current_process as current_process -import queue +from multiprocessing.queues import Queue, SimpleQueue, JoinableQueue import sys -_T = TypeVar('_T') - # N.B. The functions below are generated at runtime by partially applying # multiprocessing.context.BaseContext's methods, so the two signatures should # be identical (modulo self). @@ -62,19 +60,6 @@ class Process(): def is_alive(self) -> bool: ... def join(self, timeout: Optional[float] = ...) -> None: ... -class Queue(queue.Queue[_T]): - def __init__(self, maxsize: int = ...) -> None: ... - def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... - def put(self, item: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... - def qsize(self) -> int: ... - def empty(self) -> bool: ... - def full(self) -> bool: ... - def put_nowait(self, item: _T) -> None: ... - def get_nowait(self) -> _T: ... - def close(self) -> None: ... - def join_thread(self) -> None: ... - def cancel_join_thread(self) -> None: ... - class Value(): value: Any = ... def __init__(self, typecode_or_type: str, *args: Any, lock: bool = ...) -> None: ... diff --git a/stdlib/3/multiprocessing/context.pyi b/stdlib/3/multiprocessing/context.pyi index 859a6c3a6..359d8907c 100644 --- a/stdlib/3/multiprocessing/context.pyi +++ b/stdlib/3/multiprocessing/context.pyi @@ -3,6 +3,7 @@ from logging import Logger import multiprocessing from multiprocessing import synchronize +from multiprocessing import queues import sys from typing import ( Any, Callable, Iterable, Optional, List, Mapping, Sequence, Tuple, Type, @@ -51,12 +52,9 @@ class BaseContext(object): def RLock(self) -> synchronize.RLock: ... def Semaphore(self, value: int = ...) -> synchronize.Semaphore: ... - # TODO: change return to Queue once a stub exists in multiprocessing.queues - def Queue(self, maxsize: int = ...) -> Any: ... - # TODO: change return to Queue once a stub exists in multiprocessing.queues - def JoinableQueue(self, maxsize: int = ...) -> Any: ... - # TODO: change return to SimpleQueue once a stub exists in multiprocessing.queues - def SimpleQueue(self) -> Any: ... + def Queue(self, maxsize: int = ...) -> queues.Queue: ... + def JoinableQueue(self, maxsize: int = ...) -> queues.JoinableQueue: ... + def SimpleQueue(self) -> queues.SimpleQueue: ... def Pool( self, processes: Optional[int] = ..., diff --git a/stdlib/3/multiprocessing/queues.pyi b/stdlib/3/multiprocessing/queues.pyi new file mode 100644 index 000000000..c6dd0f20d --- /dev/null +++ b/stdlib/3/multiprocessing/queues.pyi @@ -0,0 +1,30 @@ +from typing import Any, Generic, Optional, TypeVar + +import queue + +_T = TypeVar('_T') + +class Queue(queue.Queue[_T]): + # FIXME: `ctx` is a circular dependency and it's not actually optional. + # It's marked as such to be able to use the generic Queue in __init__.pyi. + def __init__(self, maxsize: int = ..., *, ctx: Any = ...) -> None: ... + def get(self, block: bool = ..., timeout: Optional[float] = ...) -> _T: ... + def put(self, obj: _T, block: bool = ..., timeout: Optional[float] = ...) -> None: ... + def qsize(self) -> int: ... + def empty(self) -> bool: ... + def full(self) -> bool: ... + def put_nowait(self, item: _T) -> None: ... + def get_nowait(self) -> _T: ... + def close(self) -> None: ... + def join_thread(self) -> None: ... + def cancel_join_thread(self) -> None: ... + +class JoinableQueue(Queue[_T]): + def task_done(self) -> None: ... + def join(self) -> None: ... + +class SimpleQueue(Generic[_T]): + def __init__(self, *, ctx: Any = ...) -> None: ... + def empty(self) -> bool: ... + def get(self) -> _T: ... + def put(self, item: _T) -> None: ...