Skip to content

Commit de285f3

Browse files
[stdlib] Add missing pickle methods in multiprocessing.queues
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
1 parent a30db1c commit de285f3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stdlib/multiprocessing/queues.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import sys
22
from types import GenericAlias
3-
from typing import Any, Generic, TypeVar
3+
from typing import Any, Generic, NewType, TypeVar
44

55
__all__ = ["Queue", "SimpleQueue", "JoinableQueue"]
66

77
_T = TypeVar("_T")
88

9+
_QueueState = NewType("_QueueState", object)
10+
_JoinableQueueState = NewType("_JoinableQueueState", object)
11+
_SimpleQueueState = NewType("_SimpleQueueState", object)
12+
913
class Queue(Generic[_T]):
1014
# FIXME: `ctx` is a circular dependency and it's not actually optional.
1115
# It's marked as such to be able to use the generic Queue in __init__.pyi.
1216
def __init__(self, maxsize: int = 0, *, ctx: Any = ...) -> None: ...
13-
def __getstate__(self) -> object: ...
14-
def __setstate__(self, state: object) -> None: ...
17+
def __getstate__(self) -> _QueueState: ...
18+
def __setstate__(self, state: _QueueState) -> None: ...
1519
def put(self, obj: _T, block: bool = True, timeout: float | None = None) -> None: ...
1620
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
1721
def qsize(self) -> int: ...
@@ -26,15 +30,17 @@ class Queue(Generic[_T]):
2630
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
2731

2832
class JoinableQueue(Queue[_T]):
33+
def __getstate__(self) -> _JoinableQueueState: ... # type: ignore[override]
34+
def __setstate__(self, state: _JoinableQueueState) -> None: ... # type: ignore[override]
2935
def task_done(self) -> None: ...
3036
def join(self) -> None: ...
3137

3238
class SimpleQueue(Generic[_T]):
3339
def __init__(self, *, ctx: Any = ...) -> None: ...
3440
def close(self) -> None: ...
3541
def empty(self) -> bool: ...
36-
def __getstate__(self) -> object: ...
37-
def __setstate__(self, state: object) -> None: ...
42+
def __getstate__(self) -> _SimpleQueueState: ...
43+
def __setstate__(self, state: _SimpleQueueState) -> None: ...
3844
def get(self) -> _T: ...
3945
def put(self, obj: _T) -> None: ...
4046
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

0 commit comments

Comments
 (0)