Skip to content

Commit c1e708a

Browse files
AlexWaygoodtungol
andauthored
[3.13] gh-126417: Register multiprocessing proxy types to an appropriate collections.abc class (#126419) (#126435)
Co-authored-by: Stephen Morton <[email protected]>
1 parent cba17e4 commit c1e708a

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

Lib/multiprocessing/managers.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import threading
1919
import signal
2020
import array
21+
import collections.abc
2122
import queue
2223
import time
2324
import types
@@ -1167,6 +1168,7 @@ def __imul__(self, value):
11671168

11681169
__class_getitem__ = classmethod(types.GenericAlias)
11691170

1171+
collections.abc.MutableSequence.register(BaseListProxy)
11701172

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

1184+
collections.abc.MutableMapping.register(_BaseDictProxy)
11821185

11831186
ArrayProxy = MakeProxyType('ArrayProxy', (
11841187
'__len__', '__getitem__', '__setitem__'

Lib/test/_test_multiprocessing.py

+9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import functools
1717
import signal
1818
import array
19+
import collections.abc
1920
import socket
2021
import random
2122
import logging
@@ -2331,6 +2332,10 @@ def test_list(self):
23312332
a.append('hello')
23322333
self.assertEqual(f[0][:], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'hello'])
23332334

2335+
def test_list_isinstance(self):
2336+
a = self.list()
2337+
self.assertIsInstance(a, collections.abc.MutableSequence)
2338+
23342339
def test_list_iter(self):
23352340
a = self.list(list(range(10)))
23362341
it = iter(a)
@@ -2371,6 +2376,10 @@ def test_dict(self):
23712376
self.assertEqual(sorted(d.values()), [chr(i) for i in indices])
23722377
self.assertEqual(sorted(d.items()), [(i, chr(i)) for i in indices])
23732378

2379+
def test_dict_isinstance(self):
2380+
a = self.dict()
2381+
self.assertIsInstance(a, collections.abc.MutableMapping)
2382+
23742383
def test_dict_iter(self):
23752384
d = self.dict()
23762385
indices = list(range(65, 70))

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ Emily Morehouse
12701270
Derek Morr
12711271
James A Morrison
12721272
Martin Morrison
1273+
Stephen Morton
12731274
Derek McTavish Mounce
12741275
Alessandro Moura
12751276
Pablo Mouzo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Register the :class:`!multiprocessing.managers.DictProxy` and :class:`!multiprocessing.managers.ListProxy` types in
2+
:mod:`multiprocessing.managers` to :class:`collections.abc.MutableMapping` and
3+
:class:`collections.abc.MutableSequence`, respectively.

0 commit comments

Comments
 (0)