mirror of
https://github.com/python/cpython
synced 2024-09-05 08:17:45 +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
|
@ -1165,15 +1165,19 @@ def __imul__(self, value):
|
|||
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', (
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
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 @@
|
|||
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):
|
||||
|
|
|
@ -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…
Reference in a new issue