From 0b29d83158c88fc35af051ab9df706b61204083a Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 23 Oct 2024 18:53:55 -0700 Subject: [PATCH 1/2] inheritance for multiprocessing.managers.BaseListProxy --- stdlib/multiprocessing/managers.pyi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index c5a1134377a1..6c799d6c4d80 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -2,7 +2,7 @@ import queue import sys import threading from _typeshed import Incomplete, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT -from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, MutableSequence, Sequence +from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence from types import TracebackType from typing import Any, AnyStr, ClassVar, Generic, SupportsIndex, TypeVar, overload from typing_extensions import Self, TypeAlias @@ -86,10 +86,11 @@ class DictProxy(BaseProxy, MutableMapping[_KT, _VT]): if sys.version_info >= (3, 13): def __class_getitem__(cls, args: Any, /) -> Any: ... -class BaseListProxy(BaseProxy, MutableSequence[_T]): +class BaseListProxy(BaseProxy, Generic[_T]): __builtins__: ClassVar[dict[str, Any]] def __len__(self) -> int: ... def __add__(self, x: list[_T], /) -> list[_T]: ... + def __contains__(self, value: object) -> bool: ... def __delitem__(self, i: SupportsIndex | slice, /) -> None: ... @overload def __getitem__(self, i: SupportsIndex, /) -> _T: ... @@ -99,6 +100,7 @@ class BaseListProxy(BaseProxy, MutableSequence[_T]): def __setitem__(self, i: SupportsIndex, o: _T, /) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T], /) -> None: ... + def __imul__(self, value: SupportsIndex) -> Self: ... def __mul__(self, n: SupportsIndex, /) -> list[_T]: ... def __rmul__(self, n: SupportsIndex, /) -> list[_T]: ... def __reversed__(self) -> Iterator[_T]: ... @@ -109,6 +111,7 @@ class BaseListProxy(BaseProxy, MutableSequence[_T]): def count(self, value: _T, /) -> int: ... def insert(self, index: SupportsIndex, object: _T, /) -> None: ... def remove(self, value: _T, /) -> None: ... + def reverse(self) -> None: ... # Use BaseListProxy[SupportsRichComparisonT] for the first overload rather than [SupportsRichComparison] # to work around invariance @overload From a313de1d08c279bebbba18fe5260180cce4b4954 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 23 Oct 2024 19:20:51 -0700 Subject: [PATCH 2/2] small details --- stdlib/@tests/stubtest_allowlists/common.txt | 1 - stdlib/multiprocessing/managers.pyi | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 13024e94aaf3..66c7de1b3fa7 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -430,7 +430,6 @@ inspect.Signature.empty # set as private marker _empty # These multiprocessing proxy methods have *args, **kwargs signatures at runtime, # But have more precise (accurate) signatures in the stub -multiprocessing.managers.BaseListProxy.__imul__ multiprocessing.managers.BaseListProxy.__len__ multiprocessing.managers.BaseListProxy.__reversed__ multiprocessing.managers.BaseListProxy.reverse diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 6c799d6c4d80..3ab7d87f8d6f 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -90,7 +90,7 @@ class BaseListProxy(BaseProxy, Generic[_T]): __builtins__: ClassVar[dict[str, Any]] def __len__(self) -> int: ... def __add__(self, x: list[_T], /) -> list[_T]: ... - def __contains__(self, value: object) -> bool: ... + def __contains__(self, value: object, /) -> bool: ... def __delitem__(self, i: SupportsIndex | slice, /) -> None: ... @overload def __getitem__(self, i: SupportsIndex, /) -> _T: ... @@ -100,7 +100,7 @@ class BaseListProxy(BaseProxy, Generic[_T]): def __setitem__(self, i: SupportsIndex, o: _T, /) -> None: ... @overload def __setitem__(self, s: slice, o: Iterable[_T], /) -> None: ... - def __imul__(self, value: SupportsIndex) -> Self: ... + def __imul__(self, value: SupportsIndex, /) -> Self: ... def __mul__(self, n: SupportsIndex, /) -> list[_T]: ... def __rmul__(self, n: SupportsIndex, /) -> list[_T]: ... def __reversed__(self) -> Iterator[_T]: ... @@ -120,8 +120,8 @@ class BaseListProxy(BaseProxy, Generic[_T]): def sort(self, *, key: Callable[[_T], SupportsRichComparison], reverse: bool = ...) -> None: ... class ListProxy(BaseListProxy[_T]): - def __iadd__(self, value: Iterable[_T], /) -> Self: ... # type: ignore[override] - def __imul__(self, value: SupportsIndex, /) -> Self: ... # type: ignore[override] + def __iadd__(self, value: Iterable[_T]) -> Self: ... # type: ignore[override] + def __imul__(self, value: SupportsIndex) -> Self: ... # type: ignore[override] if sys.version_info >= (3, 13): def __class_getitem__(cls, args: Any, /) -> Any: ...