From 3f798141cd42a704081806ceb42c8095d93ac5fb Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Mon, 4 Nov 2024 11:44:51 -0800 Subject: [PATCH 1/5] add multiprocessing.managers._BaseDictProxy --- stdlib/multiprocessing/managers.pyi | 75 ++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 8c65eccad07a..4aeb63ae7a71 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -61,32 +61,59 @@ class ValueProxy(BaseProxy, Generic[_T]): if sys.version_info >= (3, 9): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... -class DictProxy(BaseProxy, MutableMapping[_KT, _VT]): - __builtins__: ClassVar[dict[str, Any]] - def __len__(self) -> int: ... - def __getitem__(self, key: _KT, /) -> _VT: ... - def __setitem__(self, key: _KT, value: _VT, /) -> None: ... - def __delitem__(self, key: _KT, /) -> None: ... - def __iter__(self) -> Iterator[_KT]: ... - def copy(self) -> dict[_KT, _VT]: ... - @overload # type: ignore[override] - def get(self, key: _KT, /) -> _VT | None: ... - @overload - def get(self, key: _KT, default: _VT, /) -> _VT: ... - @overload - def get(self, key: _KT, default: _T, /) -> _VT | _T: ... - @overload - def pop(self, key: _KT, /) -> _VT: ... - @overload - def pop(self, key: _KT, default: _VT, /) -> _VT: ... - @overload - def pop(self, key: _KT, default: _T, /) -> _VT | _T: ... - def keys(self) -> list[_KT]: ... # type: ignore[override] - def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override] - def values(self) -> list[_VT]: ... # type: ignore[override] - if sys.version_info >= (3, 13): +if sys.version_info >= (3, 13): + class _BaseDictProxy(BaseProxy, MutableMapping[_KT, _VT]): + __builtins__: ClassVar[dict[str, Any]] + def __len__(self) -> int: ... + def __getitem__(self, key: _KT, /) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, /) -> None: ... + def __delitem__(self, key: _KT, /) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def copy(self) -> dict[_KT, _VT]: ... + @overload # type: ignore[override] + def get(self, key: _KT, /) -> _VT | None: ... + @overload + def get(self, key: _KT, default: _VT, /) -> _VT: ... + @overload + def get(self, key: _KT, default: _T, /) -> _VT | _T: ... + @overload + def pop(self, key: _KT, /) -> _VT: ... + @overload + def pop(self, key: _KT, default: _VT, /) -> _VT: ... + @overload + def pop(self, key: _KT, default: _T, /) -> _VT | _T: ... + def keys(self) -> list[_KT]: ... # type: ignore[override] + def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override] + def values(self) -> list[_VT]: ... # type: ignore[override] + + class DictProxy(_BaseDictProxy[_KT, _VT]): def __class_getitem__(cls, args: Any, /) -> Any: ... +else: + class DictProxy(BaseProxy, MutableMapping[_KT, _VT]): + __builtins__: ClassVar[dict[str, Any]] + def __len__(self) -> int: ... + def __getitem__(self, key: _KT, /) -> _VT: ... + def __setitem__(self, key: _KT, value: _VT, /) -> None: ... + def __delitem__(self, key: _KT, /) -> None: ... + def __iter__(self) -> Iterator[_KT]: ... + def copy(self) -> dict[_KT, _VT]: ... + @overload # type: ignore[override] + def get(self, key: _KT, /) -> _VT | None: ... + @overload + def get(self, key: _KT, default: _VT, /) -> _VT: ... + @overload + def get(self, key: _KT, default: _T, /) -> _VT | _T: ... + @overload + def pop(self, key: _KT, /) -> _VT: ... + @overload + def pop(self, key: _KT, default: _VT, /) -> _VT: ... + @overload + def pop(self, key: _KT, default: _T, /) -> _VT | _T: ... + def keys(self) -> list[_KT]: ... # type: ignore[override] + def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override] + def values(self) -> list[_VT]: ... # type: ignore[override] + class BaseListProxy(BaseProxy, MutableSequence[_T]): __builtins__: ClassVar[dict[str, Any]] def __len__(self) -> int: ... From 0e1e9e15de5ded0707442f1a9c2c25b29579054b Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Mon, 4 Nov 2024 11:55:52 -0800 Subject: [PATCH 2/5] stubtest --- stdlib/@tests/stubtest_allowlists/py310.txt | 9 +++++++++ stdlib/@tests/stubtest_allowlists/py311.txt | 9 +++++++++ stdlib/@tests/stubtest_allowlists/py312.txt | 9 +++++++++ stdlib/@tests/stubtest_allowlists/py313.txt | 9 +++++++++ stdlib/@tests/stubtest_allowlists/py38.txt | 9 +++++++++ stdlib/@tests/stubtest_allowlists/py39.txt | 9 +++++++++ 6 files changed, 54 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py310.txt b/stdlib/@tests/stubtest_allowlists/py310.txt index 8d0631cdd291..e97cca7507b1 100644 --- a/stdlib/@tests/stubtest_allowlists/py310.txt +++ b/stdlib/@tests/stubtest_allowlists/py310.txt @@ -230,6 +230,15 @@ importlib.abc.Traversable.open importlib.metadata.DeprecatedList.reverse importlib.metadata.DeprecatedList.sort +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers.DictProxy.__iter__ +multiprocessing.managers.DictProxy.__len__ +multiprocessing.managers.DictProxy.copy +multiprocessing.managers.DictProxy.items +multiprocessing.managers.DictProxy.keys +multiprocessing.managers.DictProxy.values + # Super-special typing primitives typing\.NamedTuple typing\.Annotated diff --git a/stdlib/@tests/stubtest_allowlists/py311.txt b/stdlib/@tests/stubtest_allowlists/py311.txt index 308855f8f00b..80c7ae31e7be 100644 --- a/stdlib/@tests/stubtest_allowlists/py311.txt +++ b/stdlib/@tests/stubtest_allowlists/py311.txt @@ -184,6 +184,15 @@ importlib.resources.abc.Traversable.open importlib.metadata.DeprecatedList.reverse importlib.metadata.DeprecatedList.sort +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers.DictProxy.__iter__ +multiprocessing.managers.DictProxy.__len__ +multiprocessing.managers.DictProxy.copy +multiprocessing.managers.DictProxy.items +multiprocessing.managers.DictProxy.keys +multiprocessing.managers.DictProxy.values + # Super-special typing primitives typing\._SpecialForm.* typing\.NamedTuple diff --git a/stdlib/@tests/stubtest_allowlists/py312.txt b/stdlib/@tests/stubtest_allowlists/py312.txt index 14500a678fdf..84e75c493050 100644 --- a/stdlib/@tests/stubtest_allowlists/py312.txt +++ b/stdlib/@tests/stubtest_allowlists/py312.txt @@ -174,6 +174,15 @@ importlib.resources.abc.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers.DictProxy.__iter__ +multiprocessing.managers.DictProxy.__len__ +multiprocessing.managers.DictProxy.copy +multiprocessing.managers.DictProxy.items +multiprocessing.managers.DictProxy.keys +multiprocessing.managers.DictProxy.values + # Super-special typing primitives typing\._SpecialForm.* typing\.NamedTuple diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index f1dd2471203e..c962df9320f3 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -151,6 +151,15 @@ importlib.resources.abc.Traversable.open # Deprecation wrapper classes; their methods are just pass-through, so we can ignore them. importlib.metadata.DeprecatedNonAbstract.__new__ +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers._BaseDictProxy.__iter__ +multiprocessing.managers._BaseDictProxy.__len__ +multiprocessing.managers._BaseDictProxy.copy +multiprocessing.managers._BaseDictProxy.items +multiprocessing.managers._BaseDictProxy.keys +multiprocessing.managers._BaseDictProxy.values + # Super-special typing primitives typing\._SpecialForm.* typing\.NamedTuple diff --git a/stdlib/@tests/stubtest_allowlists/py38.txt b/stdlib/@tests/stubtest_allowlists/py38.txt index ace9fd78706d..6caeb654b767 100644 --- a/stdlib/@tests/stubtest_allowlists/py38.txt +++ b/stdlib/@tests/stubtest_allowlists/py38.txt @@ -266,3 +266,12 @@ email.utils.parseaddr # Weird special builtins that are typed as functions, but aren't functions hashlib.sha3_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+ hashlib.shake_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+ + +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers.DictProxy.__iter__ +multiprocessing.managers.DictProxy.__len__ +multiprocessing.managers.DictProxy.copy +multiprocessing.managers.DictProxy.items +multiprocessing.managers.DictProxy.keys +multiprocessing.managers.DictProxy.values diff --git a/stdlib/@tests/stubtest_allowlists/py39.txt b/stdlib/@tests/stubtest_allowlists/py39.txt index 9c646178b383..56302bc39de3 100644 --- a/stdlib/@tests/stubtest_allowlists/py39.txt +++ b/stdlib/@tests/stubtest_allowlists/py39.txt @@ -204,6 +204,15 @@ multiprocessing.managers.DictProxy.popitem # Problematic protocol signature at runtime, see source code comments. importlib.abc.Traversable.open +# These multiprocessing proxy methods have *args, **kwargs signatures at runtime, +# But have more precise (accurate) signatures in the stub +multiprocessing.managers.DictProxy.__iter__ +multiprocessing.managers.DictProxy.__len__ +multiprocessing.managers.DictProxy.copy +multiprocessing.managers.DictProxy.items +multiprocessing.managers.DictProxy.keys +multiprocessing.managers.DictProxy.values + # Super-special typing primitives typing\.NamedTuple typing\.Annotated From ab9b7c5617529609e6d346e1f5552cd5eaa79586 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Mon, 4 Nov 2024 11:56:57 -0800 Subject: [PATCH 3/5] missed a file for the last commit --- stdlib/@tests/stubtest_allowlists/common.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index e2f5003b32f4..98e7c3afa8d8 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -410,12 +410,6 @@ multiprocessing.managers.BaseListProxy.__len__ multiprocessing.managers.BaseListProxy.__reversed__ multiprocessing.managers.BaseListProxy.reverse multiprocessing.managers.BaseListProxy.sort -multiprocessing.managers.DictProxy.__iter__ -multiprocessing.managers.DictProxy.__len__ -multiprocessing.managers.DictProxy.copy -multiprocessing.managers.DictProxy.items -multiprocessing.managers.DictProxy.keys -multiprocessing.managers.DictProxy.values multiprocessing.(dummy|managers).Namespace.__[gs]etattr__ # Any field can be set on Namespace # alias for a class defined elsewhere, From 907e8958c2290ba93645e562a21f7bee4f8c6d3c Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Mon, 4 Nov 2024 11:59:26 -0800 Subject: [PATCH 4/5] more stubtest --- stdlib/@tests/stubtest_allowlists/py313.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index c962df9320f3..44023211f3e6 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -155,9 +155,11 @@ importlib.metadata.DeprecatedNonAbstract.__new__ # But have more precise (accurate) signatures in the stub multiprocessing.managers._BaseDictProxy.__iter__ multiprocessing.managers._BaseDictProxy.__len__ +multiprocessing.managers._BaseDictProxy.clear multiprocessing.managers._BaseDictProxy.copy multiprocessing.managers._BaseDictProxy.items multiprocessing.managers._BaseDictProxy.keys +multiprocessing.managers._BaseDictProxy.popitem multiprocessing.managers._BaseDictProxy.values # Super-special typing primitives From c049ffb4ce6c345bbc9780f599a33f245cee5ec4 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Tue, 5 Nov 2024 12:58:28 -0800 Subject: [PATCH 5/5] Update stdlib/multiprocessing/managers.pyi Co-authored-by: Alex Waygood --- stdlib/multiprocessing/managers.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/multiprocessing/managers.pyi b/stdlib/multiprocessing/managers.pyi index 4aeb63ae7a71..1669c5f09f97 100644 --- a/stdlib/multiprocessing/managers.pyi +++ b/stdlib/multiprocessing/managers.pyi @@ -87,7 +87,7 @@ if sys.version_info >= (3, 13): def values(self) -> list[_VT]: ... # type: ignore[override] class DictProxy(_BaseDictProxy[_KT, _VT]): - def __class_getitem__(cls, args: Any, /) -> Any: ... + def __class_getitem__(cls, args: Any, /) -> GenericAlias: ... else: class DictProxy(BaseProxy, MutableMapping[_KT, _VT]):