From 4fb0cd005d1d6cb8106950ee95faa7e639a82940 Mon Sep 17 00:00:00 2001 From: Nathan Brahms Date: Wed, 16 Oct 2019 19:06:25 -0700 Subject: [PATCH 1/2] multiprocessing.pool: Fix return of map_async() This commit fixes the issue raised in https://github.com/python/typeshed/issues/3377. Inspecting the multiprocessing code, it appears that MapResult is a minimal extension of AsyncResult, so I choose to remove the extra List[] type from its generic argument (alternatively one could remove it from the return type of map_async() itself, but this seems incorrect as map() has a return type of List[]). The multiprocessing.pool API appears not to have changed at least since 2.7, so this change should work for both Python 2 and 3. --- stdlib/3/multiprocessing/pool.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index 479c4f21834d..2fd8ef53d159 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -13,7 +13,7 @@ class ApplyResult(Generic[_T]): # alias created during issue #17805 AsyncResult = ApplyResult -class MapResult(ApplyResult[List[_T]]): ... +class MapResult(ApplyResult[_T]): ... class IMapIterator(Iterator[_T]): def __iter__(self: _S) -> _S: ... From 14d369bbd98bea77f08b48e3b69a47878c28567a Mon Sep 17 00:00:00 2001 From: Nathan Brahms Date: Thu, 17 Oct 2019 07:58:00 -0700 Subject: [PATCH 2/2] squash! Add PEP 593 (Annotated etc.) typing_extensions stubs (#3369) On returning to the multiprocessing.pool code, I see that MapResult does indeed always return a List type. Therefore, to fix the doubly nested list in multiprocessing.pool.map_async, we should remove the spurious List type from the map_async def instead. --- stdlib/3/multiprocessing/pool.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/3/multiprocessing/pool.pyi b/stdlib/3/multiprocessing/pool.pyi index 2fd8ef53d159..5d37644306e7 100644 --- a/stdlib/3/multiprocessing/pool.pyi +++ b/stdlib/3/multiprocessing/pool.pyi @@ -13,7 +13,7 @@ class ApplyResult(Generic[_T]): # alias created during issue #17805 AsyncResult = ApplyResult -class MapResult(ApplyResult[_T]): ... +class MapResult(ApplyResult[List[_T]]): ... class IMapIterator(Iterator[_T]): def __iter__(self: _S) -> _S: ... @@ -46,7 +46,7 @@ class Pool(ContextManager[Pool]): iterable: Iterable[_S] = ..., chunksize: Optional[int] = ..., callback: Optional[Callable[[_T], None]] = ..., - error_callback: Optional[Callable[[BaseException], None]] = ...) -> MapResult[List[_T]]: ... + error_callback: Optional[Callable[[BaseException], None]] = ...) -> MapResult[_T]: ... def imap(self, func: Callable[[_S], _T], iterable: Iterable[_S] = ...,