8000 bpo-39481: Generic Alias for SimpleQueue, Queue, TemporaryDirectory... · python/cpython@8fde377 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8fde377

Browse files
committed
bpo-39481: Generic Alias for SimpleQueue, Queue, TemporaryDirectory...
1 parent e3ec44d commit 8fde377

File tree

5 files changed

+17
-0
lines changed

5 files changed

+17
-0
lines changed

Lib/queue.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'''A multi-producer, multi-consumer queue.'''
22

33
import threading
4+
import types
45
from collections import deque
56
from heapq import heappush, heappop
67
from time import monotonic as time
@@ -216,6 +217,8 @@ def _put(self, item):
216217
def _get(self):
217218
return self.queue.popleft()
218219

220+
__class_getitem__ = classmethod(types.GenericAlias)
221+
219222

220223
class PriorityQueue(Queue):
221224
'''Variant of Queue that retrieves open entries in priority order (lowest first).
@@ -316,6 +319,8 @@ def qsize(self):
316319
'''Return the approximate size of the queue (not reliable!).'''
317320
return len(self._queue)
318321

322+
__class_getitem__ = classmethod(types.GenericAlias)
323+
319324

320325
if SimpleQueue is None:
321326
SimpleQueue = _PySimpleQueue

Lib/tempfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,5 @@ def __exit__(self, exc, value, tb):
829829
def cleanup(self):
830830
if self._finalizer.detach():
831831
self._rmtree(self.name)
832+
833+
__class_getitem__ = classmethod(_types.GenericAlias)

Lib/test/test_genericalias.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
from os import DirEntry
1717
from re import Pattern, Match
1818
from types import GenericAlias, MappingProxyType, AsyncGeneratorType
19+
from tempfile import TemporaryDirectory, SpooledTemporaryFile
20+
from unittest.case import _AssertRaisesContext
21+
from queue import Queue, SimpleQueue
1922
import typing
2023

2124
from typing import TypeVar
@@ -49,6 +52,9 @@ def test_subscriptable(self):
4952
DirEntry,
5053
IPv4Network, IPv4Interface, IPv6Network, IPv6Interface,
5154
chain,
55+
TemporaryDirectory, SpooledTemporaryFile,
56+
Queue, SimpleQueue,
57+
_AssertRaisesContext,
5258
):
5359
tname = t.__name__
5460
with self.subTest(f"Testing {tname}"):

Lib/unittest/case.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ def __exit__(self, exc_type, exc_value, tb):
241241
expected_regex.pattern, str(exc_value)))
242242
return True
243243

244+
__class_getitem__ = classmethod(types.GenericAlias)
245+
244246

245247
class _AssertWarnsContext(_AssertRaisesBaseContext):
246248
"""A context manager used to implement TestCase.assertWarns* methods."""

Modules/_queuemodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ static PyMethodDef simplequeue_methods[] = {
302302
_QUEUE_SIMPLEQUEUE_PUT_METHODDEF
303303
_QUEUE_SIMPLEQUEUE_PUT_NOWAIT_METHODDEF
304304
_QUEUE_SIMPLEQUEUE_QSIZE_METHODDEF
305+
{"__class_getitem__", (PyCFunction)Py_GenericAlias,
306+
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
305307
{NULL, NULL} /* sentinel */
306308
};
307309

0 commit comments

Comments
 (0)
0