From 2a260d50ab11d93c8adcc5cef2636013dc7d742f Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sat, 26 Oct 2024 13:51:22 -0400 Subject: [PATCH 1/5] Add __class_getitem__ to memoryview --- Doc/whatsnew/3.14.rst | 3 +++ Lib/test/test_genericalias.py | 2 +- .../2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst | 2 ++ Objects/memoryobject.c | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index d95f1848ad6d86..14a9c421bbfa84 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -194,6 +194,9 @@ Other language changes :mod:`copyable `. (Contributed by Serhiy Storchaka in :gh:`125767`.) +* The :class:`memoryview` type now supports subscripting, 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 12564b423493aa..3048d038c782d4 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -100,7 +100,7 @@ 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 00000000000000..d6842dbcedf575 --- /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 subscripting, making it a +:term:`generic type`. diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c index a2472d4873641d..d4672e8198cb24 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} }; From 6f02b089cb5b54308dfcd459303a286ecc326173 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sat, 26 Oct 2024 14:45:37 -0400 Subject: [PATCH 2/5] Update Doc/whatsnew/3.14.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 14a9c421bbfa84..f23d465ceb116f 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -194,8 +194,9 @@ Other language changes :mod:`copyable `. (Contributed by Serhiy Storchaka in :gh:`125767`.) -* The :class:`memoryview` type now supports subscripting, making it a - :term:`generic type`. (Contributed by Brian Schubert in :gh:`126012`.) +* The :class:`memoryview` type now supports subscription, + making it a :term:`generic type`. + (Contributed by Brian Schubert in :gh:`126012`.) New modules From 19c36da8d6ddd040e1b3a6de90db8328ff548e4a Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sat, 26 Oct 2024 14:45:45 -0400 Subject: [PATCH 3/5] Update Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index d6842dbcedf575..5307920ddcf200 100644 --- 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 @@ -1,2 +1,2 @@ -The :class:`memoryview` type now supports subscripting, making it a +The :class:`memoryview` type now supports subscription, making it a :term:`generic type`. From b78ab6bb1bd582d906be84c7655d86d8ef2f1b5c Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sat, 26 Oct 2024 14:54:17 -0400 Subject: [PATCH 4/5] Add versionchanged directive to memoryview docs --- Doc/library/stdtypes.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a6e2e3b8928ebe..8ebb7375bb8e50 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:: 3.14 + memoryview is now a :term:`generic type`. + :class:`memoryview` has several methods: .. method:: __eq__(exporter) From 413fa8303f6fd7f8139e0ecff54ef2841bcfcd88 Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sat, 26 Oct 2024 18:30:11 -0400 Subject: [PATCH 5/5] Update Doc/library/stdtypes.rst Co-authored-by: Peter Bierma --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 8ebb7375bb8e50..704637d675ead3 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3889,7 +3889,7 @@ copying. .. versionchanged:: 3.5 memoryviews can now be indexed with tuple of integers. - .. versionchanged:: 3.14 + .. versionchanged:: next memoryview is now a :term:`generic type`. :class:`memoryview` has several methods: