summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/multiprocessing/managers.py8
-rw-r--r--Lib/test/test_genericalias.py6
-rw-r--r--Misc/NEWS.d/next/Library/2023-07-29-19-00-39.gh-issue-107431.1GzJ2p.rst2
3 files changed, 12 insertions, 4 deletions
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index 273c22a..96cebc6 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -1165,15 +1165,19 @@ class ListProxy(BaseListProxy):
self._callmethod('__imul__', (value,))
return self
+ __class_getitem__ = classmethod(types.GenericAlias)
+
-DictProxy = MakeProxyType('DictProxy', (
+_BaseDictProxy = MakeProxyType('DictProxy', (
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
'__setitem__', 'clear', 'copy', 'get', 'items',
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
))
-DictProxy._method_to_typeid_ = {
+_BaseDictProxy._method_to_typeid_ = {
'__iter__': 'Iterator',
}
+class DictProxy(_BaseDictProxy):
+ __class_getitem__ = classmethod(types.GenericAlias)
ArrayProxy = MakeProxyType('ArrayProxy', (
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index bf600a0..04cb810 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -28,7 +28,7 @@ from fileinput import FileInput
from itertools import chain
from http.cookies import Morsel
try:
- from multiprocessing.managers import ValueProxy
+ from multiprocessing.managers import ValueProxy, DictProxy, ListProxy
from multiprocessing.pool import ApplyResult
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
from multiprocessing.queues import Queue as MPQueue
@@ -36,6 +36,8 @@ try:
except ImportError:
# _multiprocessing module is optional
ValueProxy = None
+ DictProxy = None
+ ListProxy = None
ApplyResult = None
MPSimpleQueue = None
MPQueue = None
@@ -134,7 +136,7 @@ class BaseTest(unittest.TestCase):
if ctypes is not None:
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
if ValueProxy is not None:
- generic_types.extend((ValueProxy, ApplyResult,
+ generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
MPSimpleQueue, MPQueue, MPJoinableQueue))
def test_subscriptable(self):
diff --git a/Misc/NEWS.d/next/Library/2023-07-29-19-00-39.gh-issue-107431.1GzJ2p.rst b/Misc/NEWS.d/next/Library/2023-07-29-19-00-39.gh-issue-107431.1GzJ2p.rst
new file mode 100644
index 0000000..fb5bd8c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2023-07-29-19-00-39.gh-issue-107431.1GzJ2p.rst
@@ -0,0 +1,2 @@
+Make the ``DictProxy`` and ``ListProxy`` types in :mod:`multiprocessing.managers`
+:ref:`Generic Alias Types<types-genericalias>` for ``[]`` use in typing contexts.