Skip to content

Add SetProxy and support for set operations in multiprocessing.managers for Python 3.14 #14077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 22, 2025
7 changes: 6 additions & 1 deletion stdlib/@tests/stubtest_allowlists/py314.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ multiprocessing.forkserver.main
multiprocessing.managers.BaseListProxy.clear
multiprocessing.managers.BaseListProxy.copy
multiprocessing.managers.DictProxy.__ior__
multiprocessing.managers.SyncManager.set
multiprocessing.managers._BaseDictProxy.__ior__
multiprocessing.managers._BaseDictProxy.__or__
multiprocessing.managers._BaseDictProxy.__reversed__
Expand Down Expand Up @@ -229,6 +228,12 @@ multiprocessing.managers._BaseDictProxy.keys
multiprocessing.managers._BaseDictProxy.popitem
multiprocessing.managers._BaseDictProxy.values

multiprocessing.managers._BaseSetProxy.__iter__
multiprocessing.managers._BaseSetProxy.__len__
multiprocessing.managers._BaseSetProxy.clear
multiprocessing.managers._BaseSetProxy.copy
multiprocessing.managers._BaseSetProxy.pop

# To match `dict`, we lie about the runtime, but use overloads to match the correct behavior
types.MappingProxyType.get

Expand Down
63 changes: 62 additions & 1 deletion stdlib/multiprocessing/managers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ import queue
import sys
import threading
from _typeshed import SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Sequence
from collections.abc import (
Callable,
Iterable,
Iterator,
Mapping,
MutableMapping,
MutableSequence,
MutableSet,
Sequence,
Set as AbstractSet,
)
from types import GenericAlias, TracebackType
from typing import Any, AnyStr, ClassVar, Generic, SupportsIndex, TypeVar, overload
from typing_extensions import Self, TypeAlias
Expand All @@ -18,6 +28,7 @@ __all__ = ["BaseManager", "SyncManager", "BaseProxy", "Token", "SharedMemoryMana
_T = TypeVar("_T")
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
_S = TypeVar("_S")

class Namespace:
def __init__(self, **kwds: Any) -> None: ...
Expand Down Expand Up @@ -111,6 +122,51 @@ else:
def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override]
def values(self) -> list[_VT]: ... # type: ignore[override]

if sys.version_info >= (3, 14):
class _BaseSetProxy(BaseProxy, MutableSet[_T]):
__builtins__: ClassVar[dict[str, Any]]
# Copied from builtins.set
def add(self, element: _T, /) -> None: ...
def copy(self) -> set[_T]: ...
def clear(self) -> None: ...
def difference(self, *s: Iterable[Any]) -> set[_T]: ...
def difference_update(self, *s: Iterable[Any]) -> None: ...
def discard(self, element: _T, /) -> None: ...
def intersection(self, *s: Iterable[Any]) -> set[_T]: ...
def intersection_update(self, *s: Iterable[Any]) -> None: ...
def isdisjoint(self, s: Iterable[Any], /) -> bool: ...
def issubset(self, s: Iterable[Any], /) -> bool: ...
def issuperset(self, s: Iterable[Any], /) -> bool: ...
def pop(self) -> _T: ...
def remove(self, element: _T, /) -> None: ...
def symmetric_difference(self, s: Iterable[_T], /) -> set[_T]: ...
def symmetric_difference_update(self, s: Iterable[_T], /) -> None: ...
def union(self, *s: Iterable[_S]) -> set[_T | _S]: ...
def update(self, *s: Iterable[_T]) -> None: ...
def __len__(self) -> int: ...
def __contains__(self, o: object, /) -> bool: ...
def __iter__(self) -> Iterator[_T]: ...
def __and__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ...
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
def __le__(self, value: AbstractSet[object], /) -> bool: ...
def __lt__(self, value: AbstractSet[object], /) -> bool: ...
def __ge__(self, value: AbstractSet[object], /) -> bool: ...
def __gt__(self, value: AbstractSet[object], /) -> bool: ...
def __eq__(self, value: object, /) -> bool: ...
def __rand__(self, value: AbstractSet[object], /) -> set[_T]: ...
def __ror__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[misc]
def __rsub__(self, value: AbstractSet[_T], /) -> set[_T]: ...
def __rxor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ... # type: ignore[misc]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...

class SetProxy(_BaseSetProxy[_T]): ...

class BaseListProxy(BaseProxy, MutableSequence[_T]):
__builtins__: ClassVar[dict[str, Any]]
def __len__(self) -> int: ...
Expand Down Expand Up @@ -273,6 +329,11 @@ class SyncManager(BaseManager):
def list(self, sequence: Sequence[_T], /) -> ListProxy[_T]: ...
@overload
def list(self) -> ListProxy[Any]: ...
if sys.version_info >= (3, 14):
@overload
def set(self, iterable: Iterable[_T], /) -> SetProxy[_T]: ...
@overload
def set(self) -> SetProxy[Any]: ...

class RemoteError(Exception): ...

Expand Down