mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
gh-107431: Make multiprocessing.managers.{DictProxy,ListProxy}
generic (#107433)
Make `multiprocessing.managers.{DictProxy,ListProxy}` generic for type annotation use. `ListProxy[str]` for example. Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
This commit is contained in:
parent
06c47a305d
commit
ae8116cfa9
3 changed files with 12 additions and 4 deletions
|
@ -1165,15 +1165,19 @@ class ListProxy(BaseListProxy):
|
||||||
self._callmethod('__imul__', (value,))
|
self._callmethod('__imul__', (value,))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
__class_getitem__ = classmethod(types.GenericAlias)
|
||||||
|
|
||||||
DictProxy = MakeProxyType('DictProxy', (
|
|
||||||
|
_BaseDictProxy = MakeProxyType('DictProxy', (
|
||||||
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
|
'__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
|
||||||
'__setitem__', 'clear', 'copy', 'get', 'items',
|
'__setitem__', 'clear', 'copy', 'get', 'items',
|
||||||
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
|
'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
|
||||||
))
|
))
|
||||||
DictProxy._method_to_typeid_ = {
|
_BaseDictProxy._method_to_typeid_ = {
|
||||||
'__iter__': 'Iterator',
|
'__iter__': 'Iterator',
|
||||||
}
|
}
|
||||||
|
class DictProxy(_BaseDictProxy):
|
||||||
|
__class_getitem__ = classmethod(types.GenericAlias)
|
||||||
|
|
||||||
|
|
||||||
ArrayProxy = MakeProxyType('ArrayProxy', (
|
ArrayProxy = MakeProxyType('ArrayProxy', (
|
||||||
|
|
|
@ -28,7 +28,7 @@ from fileinput import FileInput
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from http.cookies import Morsel
|
from http.cookies import Morsel
|
||||||
try:
|
try:
|
||||||
from multiprocessing.managers import ValueProxy
|
from multiprocessing.managers import ValueProxy, DictProxy, ListProxy
|
||||||
from multiprocessing.pool import ApplyResult
|
from multiprocessing.pool import ApplyResult
|
||||||
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
|
from multiprocessing.queues import SimpleQueue as MPSimpleQueue
|
||||||
from multiprocessing.queues import Queue as MPQueue
|
from multiprocessing.queues import Queue as MPQueue
|
||||||
|
@ -36,6 +36,8 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# _multiprocessing module is optional
|
# _multiprocessing module is optional
|
||||||
ValueProxy = None
|
ValueProxy = None
|
||||||
|
DictProxy = None
|
||||||
|
ListProxy = None
|
||||||
ApplyResult = None
|
ApplyResult = None
|
||||||
MPSimpleQueue = None
|
MPSimpleQueue = None
|
||||||
MPQueue = None
|
MPQueue = None
|
||||||
|
@ -134,7 +136,7 @@ class BaseTest(unittest.TestCase):
|
||||||
if ctypes is not None:
|
if ctypes is not None:
|
||||||
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
|
generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
|
||||||
if ValueProxy is not None:
|
if ValueProxy is not None:
|
||||||
generic_types.extend((ValueProxy, ApplyResult,
|
generic_types.extend((ValueProxy, DictProxy, ListProxy, ApplyResult,
|
||||||
MPSimpleQueue, MPQueue, MPJoinableQueue))
|
MPSimpleQueue, MPQueue, MPJoinableQueue))
|
||||||
|
|
||||||
def test_subscriptable(self):
|
def test_subscriptable(self):
|
||||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue