From 5cf317ade1e1b26ee02621ed84d29a73181631dc Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 31 Oct 2022 21:10:18 -0700 Subject: gh-98658: Add __class_getitem__ to array.array (#98661) Closes #98658 --- Doc/whatsnew/3.12.rst | 7 ++++++- Lib/test/test_genericalias.py | 4 +++- .../next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst | 2 ++ Modules/arraymodule.c | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 0eb2879..18751f5 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 6b2de72..6d0a556 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 0000000..8909d49 --- /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 924fbf2..d60cf26 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 */ }; -- cgit v0.12