]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126012: Add `__class_getitem__` to `memoryview` (#126013)
authorBrian Schubert <brianm.schubert@gmail.com>
Sun, 27 Oct 2024 10:36:03 +0000 (06:36 -0400)
committerGitHub <noreply@github.com>
Sun, 27 Oct 2024 10:36:03 +0000 (13:36 +0300)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/library/stdtypes.rst
Doc/whatsnew/3.14.rst
Lib/test/test_genericalias.py
Misc/NEWS.d/next/Core and Builtins/2024-10-26-13-32-48.gh-issue-126012.2KalhG.rst [new file with mode: 0644]
Objects/memoryobject.c

index a6e2e3b8928ebe605a2a838aa0aba1d5811e5228..704637d675ead3fe78507c52da4e1c5ee99b187f 100644 (file)
@@ -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)
index 1ccfa329d5546af48a2daf94e83ec6a0f2618fe6..a6f595ccf08bf4775acac5d5f3d89172f6fff329 100644 (file)
@@ -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
 ===========
index 12564b423493aab12282598f9ca565b107e0c8ae..3048d038c782d4110a86ced6169805325c8bf10c 100644 (file)
@@ -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 (file)
index 0000000..5307920
--- /dev/null
@@ -0,0 +1,2 @@
+The :class:`memoryview` type now supports subscription, making it a
+:term:`generic type`.
index a2472d4873641dcacac219d1e2b9473943d6da2f..d4672e8198cb24e83a07eadfbdc35d0f37fb3d32 100644 (file)
@@ -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}
 };