[stdlib/3/multiprocessing] Add queues.pyi, make the other stubs use it (#1879)

This commit is contained in:
Łukasz Langa
2018-02-17 01:00:44 +00:00
committed by Jelle Zijlstra
parent e7b567c1f4
commit 18ae67d040
3 changed files with 36 additions and 23 deletions

View File

@@ -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: ...

View File

@@ -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] = ...,

View File

@@ -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: ...