Skip to content

Commit ae8116c

Browse files
sobolevnAlexWaygoodgpshead
authored
gh-107431: Make multiprocessing.managers.{DictProxy,ListProxy} generic (#107433)
Make `multiprocessing.managers.{DictProxy,ListProxy}` generic for type annotation use. `ListProxy[str]` for example. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
1 parent 06c47a3 commit ae8116c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

Diff for: Lib/multiprocessing/managers.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1165,15 +1165,19 @@ def __imul__(self, value):
11651165
self._callmethod('__imul__', (value,))
11661166
return self
11671167

1168+
__class_getitem__ = classmethod(types.GenericAlias)
1169+
11681170

1169-
DictProxy = MakeProxyType('DictProxy', (
1171+
_BaseDictProxy = MakeProxyType('DictProxy', (
11701172
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
11711173
'__setitem__', 'clear', 'copy', 'get', 'items',
11721174
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
11731175
))
1174-
DictProxy._method_to_typeid_ = {
1176+
_BaseDictProxy._method_to_typeid_ = {
11751177
'__iter__': 'Iterator',
11761178
}
1179+
class DictProxy(_BaseDictProxy):
1180+
__class_getitem__ = classmethod(types.GenericAlias)
11771181

11781182

11791183
ArrayProxy = MakeProxyType('ArrayProxy', (

Diff for: Lib/test/test_genericalias.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@
2828
from itertools import chain
2929
from http.cookies import Morsel
3030
try:
31-
from multiprocessing.managers import ValueProxy
31+
from multiprocessing.managers import ValueProxy, DictProxy, ListProxy
3232
from multiprocessing.pool import ApplyResult
3333
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
3434
from multiprocessing.queues import Queue as MPQueue
3535
from multiprocessing.queues import JoinableQueue as MPJoinableQueue
3636
except ImportError:
3737
# _multiprocessing module is optional
3838
ValueProxy = None
39+
DictProxy = None
40+
ListProxy = None
3941
ApplyResult = None
4042
MPSimpleQueue = None
4143
MPQueue = None
@@ -134,7 +136,7 @@ class BaseTest(unittest.TestCase):
134136
if ctypes is not None:
135137
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
136138
if ValueProxy is not None:
137-
generic_types.extend((ValueProxy, ApplyResult,
139+
generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
138140
MPSimpleQueue, MPQueue, MPJoinableQueue))
139141

140142
def test_subscriptable(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make the ``DictProxy`` and ``ListProxy`` types in :mod:`multiprocessing.managers`
2+
:ref:`Generic Alias Types<types-genericalias>` for ``[]`` use in typing contexts.

0 commit comments

Comments
 (0)