https://github.com/python/cpython/commit/dc76a4ad3c46af3fb70361be10b8a791cd126931
commit: dc76a4ad3c46af3fb70361be10b8a791cd126931
branch: main
author: Brian Schubert <[email protected]>
committer: sobolevn <[email protected]>
date: 2024-10-27T13:36:03+03:00
summary:

gh-126012: Add `__class_getitem__` to `memoryview` (#126013)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst
M Doc/library/stdtypes.rst
M Doc/whatsnew/3.14.rst
M Lib/test/test_genericalias.py
M Objects/memoryobject.c

diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index a6e2e3b8928ebe..704637d675ead3 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 1ccfa329d5546a..a6f595ccf08bf4 100644
--- a/Doc/whatsnew/3.14.rst
+++ b/Doc/whatsnew/3.14.rst
@@ -194,6 +194,10 @@ Other language changes
   :mod:`copyable <copy>`.
   (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 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..5307920ddcf200
--- /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 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}
 };
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to