Skip to content

Commit

Permalink
[3.13] pythongh-126417: Register multiprocessing proxy types to an ap…
Browse files Browse the repository at this point in the history
…propriate collections.abc class (python#126419)

(cherry-picked from commit 78842e4)
  • Loading branch information
tungol authored and AlexWaygood committed Nov 5, 2024
1 parent cba17e4 commit 1a6c61a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import threading
import signal
import array
import collections.abc
import queue
import time
import types
Expand Down Expand Up @@ -1167,6 +1168,7 @@ def __imul__(self, value):

__class_getitem__ = classmethod(types.GenericAlias)

collections.abc.MutableSequence.register(BaseListProxy)

_BaseDictProxy = MakeProxyType('DictProxy', (
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
Expand All @@ -1179,6 +1181,7 @@ def __imul__(self, value):
class DictProxy(_BaseDictProxy):
__class_getitem__ = classmethod(types.GenericAlias)

collections.abc.MutableMapping.register(_BaseDictProxy)

ArrayProxy = MakeProxyType('ArrayProxy', (
'__len__', '__getitem__', '__setitem__'
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import functools
import signal
import array
import collections.abc
import socket
import random
import logging
Expand Down Expand Up @@ -2331,6 +2332,10 @@ def test_list(self):
a.append('hello')
self.assertEqual(f[0][:], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello'])

def test_list_isinstance(self):
a = self.list()
self.assertIsInstance(a, collections.abc.MutableSequence)

def test_list_iter(self):
a = self.list(list(range(10)))
it = iter(a)
Expand Down Expand Up @@ -2371,6 +2376,10 @@ def test_dict(self):
self.assertEqual(sorted(d.values()), [chr(i) for i in indices])
self.assertEqual(sorted(d.items()), [(i, chr(i)) for i in indices])

def test_dict_isinstance(self):
a = self.dict()
self.assertIsInstance(a, collections.abc.MutableMapping)

def test_dict_iter(self):
d = self.dict()
indices = list(range(65, 70))
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ Emily Morehouse
Derek Morr
James A Morrison
Martin Morrison
Stephen Morton
Derek McTavish Mounce
Alessandro Moura
Pablo Mouzo
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Register the :class:`!multiprocessing.managers.DictProxy` and :class:`!multiprocessing.managers.ListProxy` types in
:mod:`multiprocessing.managers` to :class:`collections.abc.MutableMapping` and
:class:`collections.abc.MutableSequence`, respectively.

0 comments on commit 1a6c61a

Please sign in to comment.