gh-99509: Add __class_getitem__ to multiprocessing.queues.Queue (#99511)

This commit is contained in:
Nikita Sobolev 2022-12-27 07:50:55 +03:00 committed by GitHub
parent 199507b81a
commit ce39aaffee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View file

@ -280,6 +280,8 @@ class Queue(object):
import traceback import traceback
traceback.print_exc() traceback.print_exc()
__class_getitem__ = classmethod(types.GenericAlias)
_sentinel = object() _sentinel = object()

View file

@ -31,11 +31,15 @@ try:
from multiprocessing.managers import ValueProxy from multiprocessing.managers import ValueProxy
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 JoinableQueue as MPJoinableQueue
except ImportError: except ImportError:
# _multiprocessing module is optional # _multiprocessing module is optional
ValueProxy = None ValueProxy = None
ApplyResult = None ApplyResult = None
MPSimpleQueue = None MPSimpleQueue = None
MPQueue = None
MPJoinableQueue = None
try: try:
from multiprocessing.shared_memory import ShareableList from multiprocessing.shared_memory import ShareableList
except ImportError: except ImportError:
@ -130,7 +134,8 @@ 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, MPSimpleQueue)) generic_types.extend((ValueProxy, ApplyResult,
MPSimpleQueue, MPQueue, MPJoinableQueue))
def test_subscriptable(self): def test_subscriptable(self):
for t in self.generic_types: for t in self.generic_types:

View file

@ -0,0 +1 @@
Add :pep:`585` support for :class:`multiprocessing.queues.Queue`.