Skip to content

Commit 47d48b6

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

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Lib/multiprocessing/managers.py

Lines changed: 4 additions & 0 deletions
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
@@ -1160,6 +1161,8 @@ def __imul__(self, value):
11601161
return self
11611162

11621163

1164+
collections.abc.MutableSequence.register(BaseListProxy)
1165+
11631166
DictProxy = MakeProxyType('DictProxy', (
11641167
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
11651168
'__setitem__', 'clear', 'copy', 'get', 'items',
@@ -1169,6 +1172,7 @@ def __imul__(self, value):
11691172
'__iter__': 'Iterator',
11701173
}
11711174

1175+
collections.abc.MutableMapping.register(DictProxy)
11721176

11731177
ArrayProxy = MakeProxyType('ArrayProxy', (
11741178
'__len__', '__getitem__', '__setitem__'

Lib/test/_test_multiprocessing.py

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,7 @@ Emily Morehouse
12591259
Derek Morr
12601260
James A Morrison
12611261
Martin Morrison
1262+
Stephen Morton
12621263
Derek McTavish Mounce
12631264
Alessandro Moura
12641265
Pablo Mouzo
Lines changed: 3 additions & 0 deletions
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)