Skip to content

Commit

Permalink
pythongh-107431: Make `multiprocessing.managers.{DictProxy,ListProxy}…
Browse files Browse the repository at this point in the history
…` generic
  • Loading branch information
sobolevn committed Jul 29, 2023
1 parent 2aaa83d commit 3f865c5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,16 +1159,21 @@ def __imul__(self, value):
self._callmethod('__imul__', (value,))
return self

__class_getitem__ = classmethod(types.GenericAlias)


DictProxy = MakeProxyType('DictProxy', (
BaseDictProxy = MakeProxyType('DictProxy', (
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
'__setitem__', 'clear', 'copy', 'get', 'items',
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values',
))
DictProxy._method_to_typeid_ = {
'__iter__': 'Iterator',
class DictProxy(BaseDictProxy):
_method_to_typeid_ = {
'__iter__': 'Iterator',
}

__class_getitem__ = classmethod(types.GenericAlias)


ArrayProxy = MakeProxyType('ArrayProxy', (
'__len__', '__getitem__', '__setitem__'
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_genericalias.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@
from itertools import chain
from http.cookies import Morsel
try:
from multiprocessing.managers import ValueProxy
from multiprocessing.managers import ValueProxy, DictProxy, ListProxy
from multiprocessing.pool import ApplyResult
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
from multiprocessing.queues import Queue as MPQueue
from multiprocessing.queues import JoinableQueue as MPJoinableQueue
except ImportError:
# _multiprocessing module is optional
ValueProxy = None
DictProxy = None
ListProxy = None
ApplyResult = None
MPSimpleQueue = None
MPQueue = None
Expand Down Expand Up @@ -134,7 +136,7 @@ class BaseTest(unittest.TestCase):
if ctypes is not None:
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
if ValueProxy is not None:
generic_types.extend((ValueProxy, ApplyResult,
generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
MPSimpleQueue, MPQueue, MPJoinableQueue))

def test_subscriptable(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Make ``DictProxy`` and ``ListProxy`` types in ``multiprocessing.managers``
generic.

0 comments on commit 3f865c5

Please sign in to comment.