Skip to content

Commit 78842e4

Browse files
authored
pythongh-126417: Register multiprocessing proxy types to an appropriate collections.abc class (python#126419)
1 parent 1371295 commit 78842e4

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Lib/multiprocessing/managers.py

+5-1
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,8 +1168,9 @@ def __imul__(self, value):
11671168

11681169
__class_getitem__ = classmethod(types.GenericAlias)
11691170

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

1171-
_BaseDictProxy = MakeProxyType('DictProxy', (
1173+
_BaseDictProxy = MakeProxyType('_BaseDictProxy', (
11721174
'__contains__', '__delitem__', '__getitem__', '__ior__', '__iter__',
11731175
'__len__', '__or__', '__reversed__', '__ror__',
11741176
'__setitem__', 'clear', 'copy', 'fromkeys', 'get', 'items',
@@ -1184,6 +1186,8 @@ def __ior__(self, value):
11841186

11851187
__class_getitem__ = classmethod(types.GenericAlias)
11861188

1189+
collections.abc.MutableMapping.register(_BaseDictProxy)
1190+
11871191
ArrayProxy = MakeProxyType('ArrayProxy', (
11881192
'__len__', '__getitem__', '__setitem__'
11891193
))

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
@@ -1273,6 +1273,7 @@ Emily Morehouse
12731273
Derek Morr
12741274
James A Morrison
12751275
Martin Morrison
1276+
Stephen Morton
12761277
Derek McTavish Mounce
12771278
Alessandro Moura
12781279
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)