From 16843f64fb8bf0837ecce577779a53cdf88d6a51 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Sat, 5 Aug 2017 21:06:23 -0700 Subject: [PATCH] Make multiprocessing.Queue a subclass of queue.Queue Also change multiprocessing.Queue's put and get timeout arguments to allow None. This fixes a problem with logging.handlers.QueueHandler and QueueListener not accepting a multiprocessing.Queue as the queue argument. Declaring the Queue now needs to note what it will be used for. eg. q = multiprocessing.Queue() # type: multiprocessing.Queue[List[Any]] --- stdlib/3/multiprocessing/__init__.pyi | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/stdlib/3/multiprocessing/__init__.pyi b/stdlib/3/multiprocessing/__init__.pyi index 1ff98c3d5704..1acad6412775 100644 --- a/stdlib/3/multiprocessing/__init__.pyi +++ b/stdlib/3/multiprocessing/__init__.pyi @@ -1,6 +1,6 @@ # Stubs for multiprocessing -from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List, Union +from typing import Any, Callable, Iterable, Mapping, Optional, Dict, List, Union, TypeVar from logging import Logger from multiprocessing.context import BaseContext @@ -8,6 +8,9 @@ from multiprocessing.managers import SyncManager from multiprocessing.pool import AsyncResult from multiprocessing.process import current_process as current_process import sys +import queue + +_T = TypeVar('_T') class Lock(): def acquire(self, block: bool = ..., timeout: int = ...) -> None: ... @@ -93,15 +96,15 @@ class Process(): def is_alive(self) -> bool: ... def join(self, timeout: Optional[float] = ...) -> None: ... -class Queue(): +class Queue(queue.Queue[_T]): def __init__(self, maxsize: int = ...) -> None: ... - def get(self, block: bool = ..., timeout: float = ...) -> Any: ... - def put(self, item: Any, block: bool = ..., timeout: float = ...) -> 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: Any) -> None: ... - def get_nowait(self) -> Any: ... + 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: ...