]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98658: Add __class_getitem__ to array.array (#98661)
authorJelle Zijlstra <jelle.zijlstra@gmail.com>
Tue, 1 Nov 2022 04:10:18 +0000 (21:10 -0700)
committerGitHub <noreply@github.com>
Tue, 1 Nov 2022 04:10:18 +0000 (21:10 -0700)
Closes #98658

Doc/whatsnew/3.12.rst
Lib/test/test_genericalias.py
Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst [new file with mode: 0644]
Modules/arraymodule.c

index 0eb28799a4f5fa4896327717e1db04e4dc70de41..18751f5a8c0b859cf950f3963ffccb7a3ccc12e4 100644 (file)
@@ -118,6 +118,12 @@ New Modules
 Improved Modules
 ================
 
+array
+-----
+
+* The :class:`array.array` class now supports subscripting, making it a
+  :term:`generic type`. (Contributed by Jelle Zijlstra in :gh:`98658`.)
+
 asyncio
 -------
 
@@ -141,7 +147,6 @@ asyncio
   and will be removed in Python 3.14.
   (Contributed by Kumar Aditya in :gh:`94597`.)
 
-
 pathlib
 -------
 
index 6b2de724af6b2a92702192565f7a4b4c6b25c739..6d0a556b1f7fe2f4701295eff7fb5978d7d09465 100644 (file)
@@ -2,6 +2,7 @@
 
 import unittest
 import pickle
+from array import array
 import copy
 from collections import (
     defaultdict, deque, OrderedDict, Counter, UserDict, UserList
@@ -124,7 +125,8 @@ class BaseTest(unittest.TestCase):
                      ShareableList,
                      Future, _WorkItem,
                      Morsel,
-                     DictReader, DictWriter]
+                     DictReader, DictWriter,
+                     array]
     if ctypes is not None:
         generic_types.extend((ctypes.Array, ctypes.LibraryLoader))
     if ValueProxy is not None:
diff --git a/Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst b/Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst
new file mode 100644 (file)
index 0000000..8909d49
--- /dev/null
@@ -0,0 +1,2 @@
+The :class:`array.array` class now supports subscripting, making it a
+:term:`generic type`.
index 924fbf29bfb88950363dcc0f9968e2b0710c0d82..d60cf26788f5a6d9b9f7b2b24d94fafd43de17ab 100644 (file)
@@ -2303,6 +2303,7 @@ static PyMethodDef array_methods[] = {
     ARRAY_ARRAY_TOBYTES_METHODDEF
     ARRAY_ARRAY_TOUNICODE_METHODDEF
     ARRAY_ARRAY___SIZEOF___METHODDEF
+    {"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
     {NULL, NULL}  /* sentinel */
 };