diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a6e2e3b8928..704637d675e 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3889,6 +3889,9 @@ copying. .. versionchanged:: 3.5 memoryviews can now be indexed with tuple of integers. + .. versionchanged:: next + memoryview is now a :term:`generic type`. + :class:`memoryview` has several methods: .. method:: __eq__(exporter) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 1ccfa329d55..a6f595ccf08 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -194,6 +194,10 @@ Other language changes :mod:`copyable `. (Contributed by Serhiy Storchaka in :gh:`125767`.) +* The :class:`memoryview` type now supports subscription, + making it a :term:`generic type`. + (Contributed by Brian Schubert in :gh:`126012`.) + New modules =========== diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 12564b42349..3048d038c78 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -100,7 +100,7 @@ _UNPACKED_TUPLES = [ class BaseTest(unittest.TestCase): """Test basics.""" - generic_types = [type, tuple, list, dict, set, frozenset, enumerate, + generic_types = [type, tuple, list, dict, set, frozenset, enumerate, memoryview, defaultdict, deque, SequenceMatcher, dircmp, diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst b/Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst new file mode 100644 index 00000000000..5307920ddcf --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst @@ -0,0 +1,2 @@ +The :class:`memoryview` type now supports subscription, making it a +:term:`generic type`. diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index a2472d48736..d4672e8198c 100644 --- a/Objects/memoryobject.c +++ b/Objects/memoryobject.c @@ -3286,6 +3286,7 @@ static PyMethodDef memory_methods[] = { MEMORYVIEW__FROM_FLAGS_METHODDEF {"__enter__", memory_enter, METH_NOARGS, NULL}, {"__exit__", memory_exit, METH_VARARGS, memory_exit_doc}, + {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")}, {NULL, NULL} };