diff options
author | James Hilton-Balfe <gobot1234yt@gmail.com> | 2024-05-07 01:41:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-07 01:41:32 (GMT) |
commit | e7dafdc2240a8e4e45f53782c47120eb3fe37712 (patch) | |
tree | 6ff7070c1f48907643b1354b2726d4c268befa15 | |
parent | b4bdf83cc67434235d9630c92c84a5261992b235 (diff) | |
download | cpython-e7dafdc2240a8e4e45f53782c47120eb3fe37712.zip cpython-e7dafdc2240a8e4e45f53782c47120eb3fe37712.tar.gz cpython-e7dafdc2240a8e4e45f53782c47120eb3fe37712.tar.bz2 |
gh-110209: Add __class_getitem__ for generator and coroutine (#110212)
-rw-r--r-- | Lib/test/test_genericalias.py | 3 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2023-10-02-10-35-58.gh-issue-110209.b5zfIz.rst | 1 | ||||
-rw-r--r-- | Objects/genobject.c | 2 |
3 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 04cb810..04122fb 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -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, diff --git a/Misc/NEWS.d/next/Library/2023-10-02-10-35-58.gh-issue-110209.b5zfIz.rst b/Misc/NEWS.d/next/Library/2023-10-02-10-35-58.gh-issue-110209.b5zfIz.rst new file mode 100644 index 0000000..b88e80d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-02-10-35-58.gh-issue-110209.b5zfIz.rst @@ -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. diff --git a/Objects/genobject.c b/Objects/genobject.c index acdcf57..92cd8c6 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -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 */ }; |