Skip to content

Commit 074cef0

Browse files
tungolAlexWaygood
andauthored
add multiprocessing.managers._BaseDictProxy (#12951)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 94f458f commit 074cef0

File tree

8 files changed

+108
-31
lines changed

8 files changed

+108
-31
lines changed

stdlib/@tests/stubtest_allowlists/common.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,6 @@ multiprocessing.managers.BaseListProxy.__len__
423423
multiprocessing.managers.BaseListProxy.__reversed__
424424
multiprocessing.managers.BaseListProxy.reverse
425425
multiprocessing.managers.BaseListProxy.sort
426-
multiprocessing.managers.DictProxy.__iter__
427-
multiprocessing.managers.DictProxy.__len__
428-
multiprocessing.managers.DictProxy.copy
429-
multiprocessing.managers.DictProxy.items
430-
multiprocessing.managers.DictProxy.keys
431-
multiprocessing.managers.DictProxy.values
432426

433427
# runtime is *args, **kwargs due to a wrapper, but we have more accurate signatures in the stubs
434428
multiprocessing.managers.SyncManager.Event

stdlib/@tests/stubtest_allowlists/py310.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ importlib.abc.Traversable.open
230230
importlib.metadata.DeprecatedList.reverse
231231
importlib.metadata.DeprecatedList.sort
232232

233+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
234+
# But have more precise (accurate) signatures in the stub
235+
multiprocessing.managers.DictProxy.__iter__
236+
multiprocessing.managers.DictProxy.__len__
237+
multiprocessing.managers.DictProxy.copy
238+
multiprocessing.managers.DictProxy.items
239+
multiprocessing.managers.DictProxy.keys
240+
multiprocessing.managers.DictProxy.values
241+
233242
# Super-special typing primitives
234243
typing\.NamedTuple
235244
typing\.Annotated

stdlib/@tests/stubtest_allowlists/py311.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ importlib.resources.abc.Traversable.open
184184
importlib.metadata.DeprecatedList.reverse
185185
importlib.metadata.DeprecatedList.sort
186186

187+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
188+
# But have more precise (accurate) signatures in the stub
189+
multiprocessing.managers.DictProxy.__iter__
190+
multiprocessing.managers.DictProxy.__len__
191+
multiprocessing.managers.DictProxy.copy
192+
multiprocessing.managers.DictProxy.items
193+
multiprocessing.managers.DictProxy.keys
194+
multiprocessing.managers.DictProxy.values
195+
187196
# Super-special typing primitives
188197
typing\._SpecialForm.*
189198
typing\.NamedTuple

stdlib/@tests/stubtest_allowlists/py312.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,15 @@ importlib.resources.abc.Traversable.open
174174
# Deprecation wrapper classes; their methods are just pass-through, so we can ignore them.
175175
importlib.metadata.DeprecatedNonAbstract.__new__
176176

177+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
178+
# But have more precise (accurate) signatures in the stub
179+
multiprocessing.managers.DictProxy.__iter__
180+
multiprocessing.managers.DictProxy.__len__
181+
multiprocessing.managers.DictProxy.copy
182+
multiprocessing.managers.DictProxy.items
183+
multiprocessing.managers.DictProxy.keys
184+
multiprocessing.managers.DictProxy.values
185+
177186
# Super-special typing primitives
178187
typing\._SpecialForm.*
179188
typing\.NamedTuple

stdlib/@tests/stubtest_allowlists/py313.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ importlib.resources.abc.Traversable.open
150150
# Deprecation wrapper classes; their methods are just pass-through, so we can ignore them.
151151
importlib.metadata.DeprecatedNonAbstract.__new__
152152

153+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
154+
# But have more precise (accurate) signatures in the stub
155+
multiprocessing.managers._BaseDictProxy.__iter__
156+
multiprocessing.managers._BaseDictProxy.__len__
157+
multiprocessing.managers._BaseDictProxy.clear
158+
multiprocessing.managers._BaseDictProxy.copy
159+
multiprocessing.managers._BaseDictProxy.items
160+
multiprocessing.managers._BaseDictProxy.keys
161+
multiprocessing.managers._BaseDictProxy.popitem
162+
multiprocessing.managers._BaseDictProxy.values
163+
153164
# Super-special typing primitives
154165
typing\._SpecialForm.*
155166
typing\.NamedTuple

stdlib/@tests/stubtest_allowlists/py38.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,12 @@ email.utils.parseaddr
266266
# Weird special builtins that are typed as functions, but aren't functions
267267
hashlib.sha3_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+
268268
hashlib.shake_\d+ # Class in 3.8, can't be subclassed at runtime, built-in function 3.9+
269+
270+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
271+
# But have more precise (accurate) signatures in the stub
272+
multiprocessing.managers.DictProxy.__iter__
273+
multiprocessing.managers.DictProxy.__len__
274+
multiprocessing.managers.DictProxy.copy
275+
multiprocessing.managers.DictProxy.items
276+
multiprocessing.managers.DictProxy.keys
277+
multiprocessing.managers.DictProxy.values

stdlib/@tests/stubtest_allowlists/py39.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,15 @@ multiprocessing.managers.DictProxy.popitem
204204
# Problematic protocol signature at runtime, see source code comments.
205205
importlib.abc.Traversable.open
206206

207+
# These multiprocessing proxy methods have *args, **kwargs signatures at runtime,
208+
# But have more precise (accurate) signatures in the stub
209+
multiprocessing.managers.DictProxy.__iter__
210+
multiprocessing.managers.DictProxy.__len__
211+
multiprocessing.managers.DictProxy.copy
212+
multiprocessing.managers.DictProxy.items
213+
multiprocessing.managers.DictProxy.keys
214+
multiprocessing.managers.DictProxy.values
215+
207216
# Super-special typing primitives
208217
typing\.NamedTuple
209218
typing\.Annotated

stdlib/multiprocessing/managers.pyi

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,58 @@ class ValueProxy(BaseProxy, Generic[_T]):
6161
if sys.version_info >= (3, 9):
6262
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
6363

64-
class DictProxy(BaseProxy, MutableMapping[_KT, _VT]):
65-
__builtins__: ClassVar[dict[str, Any]]
66-
def __len__(self) -> int: ...
67-
def __getitem__(self, key: _KT, /) -> _VT: ...
68-
def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
69-
def __delitem__(self, key: _KT, /) -> None: ...
70-
def __iter__(self) -> Iterator[_KT]: ...
71-
def copy(self) -> dict[_KT, _VT]: ...
72-
@overload # type: ignore[override]
73-
def get(self, key: _KT, /) -> _VT | None: ...
74-
@overload
75-
def get(self, key: _KT, default: _VT, /) -> _VT: ...
76-
@overload
77-
def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
78-
@overload
79-
def pop(self, key: _KT, /) -> _VT: ...
80-
@overload
81-
def pop(self, key: _KT, default: _VT, /) -> _VT: ...
82-
@overload
83-
def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
84-
def keys(self) -> list[_KT]: ... # type: ignore[override]
85-
def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override]
86-
def values(self) -> list[_VT]: ... # type: ignore[override]
87-
if sys.version_info >= (3, 13):
88-
def __class_getitem__(cls, args: Any, /) -> Any: ...
64+
if sys.version_info >= (3, 13):
65+
class _BaseDictProxy(BaseProxy, MutableMapping[_KT, _VT]):
66+
__builtins__: ClassVar[dict[str, Any]]
67+
def __len__(self) -> int: ...
68+
def __getitem__(self, key: _KT, /) -> _VT: ...
69+
def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
70+
def __delitem__(self, key: _KT, /) -> None: ...
71+
def __iter__(self) -> Iterator[_KT]: ...
72+
def copy(self) -> dict[_KT, _VT]: ...
73+
@overload # type: ignore[override]
74+
def get(self, key: _KT, /) -> _VT | None: ...
75+
@overload
76+
def get(self, key: _KT, default: _VT, /) -> _VT: ...
77+
@overload
78+
def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
79+
@overload
80+
def pop(self, key: _KT, /) -> _VT: ...
81+
@overload
82+
def pop(self, key: _KT, default: _VT, /) -> _VT: ...
83+
@overload
84+
def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
85+
def keys(self) -> list[_KT]: ... # type: ignore[override]
86+
def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override]
87+
def values(self) -> list[_VT]: ... # type: ignore[override]
88+
89+
class DictProxy(_BaseDictProxy[_KT, _VT]):
90+
def __class_getitem__(cls, args: Any, /) -> GenericAlias: ...
91+
92+
else:
93+
class DictProxy(BaseProxy, MutableMapping[_KT, _VT]):
94+
__builtins__: ClassVar[dict[str, Any]]
95+
def __len__(self) -> int: ...
96+
def __getitem__(self, key: _KT, /) -> _VT: ...
97+
def __setitem__(self, key: _KT, value: _VT, /) -> None: ...
98+
def __delitem__(self, key: _KT, /) -> None: ...
99+
def __iter__(self) -> Iterator[_KT]: ...
100+
def copy(self) -> dict[_KT, _VT]: ...
101+
@overload # type: ignore[override]
102+
def get(self, key: _KT, /) -> _VT | None: ...
103+
@overload
104+
def get(self, key: _KT, default: _VT, /) -> _VT: ...
105+
@overload
106+
def get(self, key: _KT, default: _T, /) -> _VT | _T: ...
107+
@overload
108+
def pop(self, key: _KT, /) -> _VT: ...
109+
@overload
110+
def pop(self, key: _KT, default: _VT, /) -> _VT: ...
111+
@overload
112+
def pop(self, key: _KT, default: _T, /) -> _VT | _T: ...
113+
def keys(self) -> list[_KT]: ... # type: ignore[override]
114+
def items(self) -> list[tuple[_KT, _VT]]: ... # type: ignore[override]
115+
def values(self) -> list[_VT]: ... # type: ignore[override]
89116

90117
class BaseListProxy(BaseProxy, MutableSequence[_T]):
91118
__builtins__: ClassVar[dict[str, Any]]

0 commit comments

Comments
 (0)