[Python-checkins] gh-98658: Add __class_getitem__ to array.array (#98661)
JelleZijlstra
webhook-mailer at python.org
Tue Nov 1 00:10:24 EDT 2022
https://github.com/python/cpython/commit/5cf317ade1e1b26ee02621ed84d29a73181631dc
commit: 5cf317ade1e1b26ee02621ed84d29a73181631dc
branch: main
author: Jelle Zijlstra <jelle.zijlstra at gmail.com>
committer: JelleZijlstra <jelle.zijlstra at gmail.com>
date: 2022-10-31T21:10:18-07:00
summary:
gh-98658: Add __class_getitem__ to array.array (#98661)
Closes #98658
files:
A Misc/NEWS.d/next/Library/2022-10-25-07-00-31.gh-issue-98658.nGABW9.rst
M Doc/whatsnew/3.12.rst
M Lib/test/test_genericalias.py
M Modules/arraymodule.c
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 */
};
More information about the Python-checkins
mailing list