]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126417: Register multiprocessing proxy types to an appropriate collections.abc...
authorStephen Morton <github@tungol.org>
Tue, 5 Nov 2024 10:05:45 +0000 (02:05 -0800)
committerGitHub <noreply@github.com>
Tue, 5 Nov 2024 10:05:45 +0000 (15:35 +0530)
Lib/multiprocessing/managers.py
Lib/test/_test_multiprocessing.py
Misc/ACKS
Misc/NEWS.d/next/Library/2024-11-04-16-40-02.gh-issue-126417.OWPqn0.rst [new file with mode: 0644]

index 0f5f9f64c2de9e0f19b51ff59c7ec749fc68e10e..a5d2f53613952e191a2e1d77f938dcb5cfef651f 100644 (file)
@@ -18,6 +18,7 @@ import sys
 import threading
 import signal
 import array
+import collections.abc
 import queue
 import time
 import types
@@ -1167,8 +1168,9 @@ class ListProxy(BaseListProxy):
 
     __class_getitem__ = classmethod(types.GenericAlias)
 
+collections.abc.MutableSequence.register(BaseListProxy)
 
-_BaseDictProxy = MakeProxyType('DictProxy', (
+_BaseDictProxy = MakeProxyType('_BaseDictProxy', (
     '__contains__', '__delitem__', '__getitem__', '__ior__', '__iter__',
     '__len__', '__or__', '__reversed__', '__ror__',
     '__setitem__', 'clear', 'copy', 'fromkeys', 'get', 'items',
@@ -1184,6 +1186,8 @@ class DictProxy(_BaseDictProxy):
 
     __class_getitem__ = classmethod(types.GenericAlias)
 
+collections.abc.MutableMapping.register(_BaseDictProxy)
+
 ArrayProxy = MakeProxyType('ArrayProxy', (
     '__len__', '__getitem__', '__setitem__'
     ))
index 065fc27b770438380db6fffa9b4e89b595975cf2..77b618c684475a51907250ed18cf035c2aef725a 100644 (file)
@@ -16,6 +16,7 @@ import errno
 import functools
 import signal
 import array
+import collections.abc
 import socket
 import random
 import logging
@@ -2331,6 +2332,10 @@ class _TestContainers(BaseTestCase):
         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)
@@ -2371,6 +2376,10 @@ class _TestContainers(BaseTestCase):
         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))
index 5e36eda554af0f87d6de9812ef6224cf57220e2d..d03c70f6db87bfe7001fe333253821bb22c43fa9 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1273,6 +1273,7 @@ Emily Morehouse
 Derek Morr
 James A Morrison
 Martin Morrison
+Stephen Morton
 Derek McTavish Mounce
 Alessandro Moura
 Pablo Mouzo
diff --git a/Misc/NEWS.d/next/Library/2024-11-04-16-40-02.gh-issue-126417.OWPqn0.rst b/Misc/NEWS.d/next/Library/2024-11-04-16-40-02.gh-issue-126417.OWPqn0.rst
new file mode 100644 (file)
index 0000000..c4a3663
--- /dev/null
@@ -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.