Skip to content

Commit 9e6b58f

Browse files
[multiprocessing.queues] Add missing pickle methods (#15424)
1 parent 789bc53 commit 9e6b58f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

stdlib/multiprocessing/queues.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +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: ...
17+
def __getstate__(self) -> _QueueState: ...
18+
def __setstate__(self, state: _QueueState) -> None: ...
1319
def put(self, obj: _T, block: bool = True, timeout: float | None = None) -> None: ...
1420
def get(self, block: bool = True, timeout: float | None = None) -> _T: ...
1521
def qsize(self) -> int: ...
@@ -24,13 +30,17 @@ class Queue(Generic[_T]):
2430
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
2531

2632
class JoinableQueue(Queue[_T]):
33+
def __getstate__(self) -> _JoinableQueueState: ... # type: ignore[override]
34+
def __setstate__(self, state: _JoinableQueueState) -> None: ... # type: ignore[override]
2735
def task_done(self) -> None: ...
2836
def join(self) -> None: ...
2937

3038
class SimpleQueue(Generic[_T]):
3139
def __init__(self, *, ctx: Any = ...) -> None: ...
3240
def close(self) -> None: ...
3341
def empty(self) -> bool: ...
42+
def __getstate__(self) -> _SimpleQueueState: ...
43+
def __setstate__(self, state: _SimpleQueueState) -> None: ...
3444
def get(self) -> _T: ...
3545
def put(self, obj: _T) -> None: ...
3646
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

0 commit comments

Comments
 (0)