Skip to content

Commit e7dafdc

Browse files
authored
gh-110209: Add __class_getitem__ for generator and coroutine (#110212)
1 parent b4bdf83 commit e7dafdc

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

Lib/test/test_genericalias.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
ShareableList = None
5050
from os import DirEntry
5151
from re import Pattern, Match
52-
from types import GenericAlias, MappingProxyType, AsyncGeneratorType
52+
from types import GenericAlias, MappingProxyType, AsyncGeneratorType, CoroutineType, GeneratorType
5353
from tempfile import TemporaryDirectory, SpooledTemporaryFile
5454
from urllib.parse import SplitResult, ParseResult
5555
from unittest.case import _AssertRaisesContext
@@ -120,6 +120,7 @@ class BaseTest(unittest.TestCase):
120120
KeysView, ItemsView, ValuesView,
121121
Sequence, MutableSequence,
122122
MappingProxyType, AsyncGeneratorType,
123+
GeneratorType, CoroutineType,
123124
DirEntry,
124125
chain,
125126
LoggerAdapter, StreamHandler,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add :meth:`~object.__class_getitem__` to :class:`types.GeneratorType` and :class:`types.CoroutineType` for type hinting purposes. Patch by James Hilton-Balfe.

Objects/genobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ static PyMethodDef gen_methods[] = {
799799
{"throw",_PyCFunction_CAST(gen_throw), METH_FASTCALL, throw_doc},
800800
{"close",(PyCFunction)gen_close, METH_NOARGS, close_doc},
801801
{"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
802+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
802803
{NULL, NULL} /* Sentinel */
803804
};
804805

@@ -1151,6 +1152,7 @@ static PyMethodDef coro_methods[] = {
11511152
{"throw",_PyCFunction_CAST(gen_throw), METH_FASTCALL, coro_throw_doc},
11521153
{"close",(PyCFunction)gen_close, METH_NOARGS, coro_close_doc},
11531154
{"__sizeof__", (PyCFunction)gen_sizeof, METH_NOARGS, sizeof__doc__},
1155+
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
11541156
{NULL, NULL} /* Sentinel */
11551157
};
11561158

0 commit comments

Comments
 (0)