From: Jelle Zijlstra Date: Tue, 1 Nov 2022 04:10:18 +0000 (-0700) Subject: gh-98658: Add __class_getitem__ to array.array (#98661) X-Git-Tag: v3.12.0a2~180 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5cf317ade1e1b26ee02621ed84d29a73181631dc;p=thirdparty%2FPython%2Fcpython.git gh-98658: Add __class_getitem__ to array.array (#98661) Closes #98658 --- diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 0eb28799a4f5..18751f5a8c0b 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -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 ------- diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py index 6b2de724af6b..6d0a556b1f7f 100644 --- a/Lib/test/test_genericalias.py +++ b/Lib/test/test_genericalias.py @@ -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 index 000000000000..8909d4941662 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst @@ -0,0 +1,2 @@ +The :class:`array.array` class now supports subscripting, making it a +:term:`generic type`. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 924fbf29bfb8..d60cf26788f5 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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 */ };