gh-110209: Add __class_getitem__ for generator and coroutine (#110212)

This commit is contained in:
James Hilton-Balfe 2024-05-07 02:41:32 +01:00 committed by GitHub
parent b4bdf83cc6
commit e7dafdc224
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 1 deletions

View File

@ -49,7 +49,7 @@ except ImportError:
ShareableList = None
from os import DirEntry
from re import Pattern, Match
from types import GenericAlias, MappingProxyType, AsyncGeneratorType
from types import GenericAlias, MappingProxyType, AsyncGeneratorType, CoroutineType, GeneratorType
from tempfile import TemporaryDirectory, SpooledTemporaryFile
from urllib.parse import SplitResult, ParseResult
from unittest.case import _AssertRaisesContext
@ -120,6 +120,7 @@ class BaseTest(unittest.TestCase):
KeysView, ItemsView, ValuesView,
Sequence, MutableSequence,
MappingProxyType, AsyncGeneratorType,
GeneratorType, CoroutineType,
DirEntry,
chain,
LoggerAdapter, StreamHandler,

View File

@ -0,0 +1 @@
Add :meth:`~object.__class_getitem__` to :class:`types.GeneratorType` and :class:`types.CoroutineType` for type hinting purposes. Patch by James Hilton-Balfe.

View File

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