From 7441b57b0d90d2beab60f59bd4521797a1594e25 Mon Sep 17 00:00:00 2001 From: Dmitry Voropaev Date: Thu, 24 Sep 2026 01:21:20 +0300 Subject: [PATCH 1/2] gh-142083: Document the 'w' type code in the array.array docstring The type code table in the array.array docstring did not list the 'w' type code, although array.typecodes has included it since 3.13. The other points raised in the issue concerned the 'u' type code, which no longer exists: it was removed, together with its note about narrow and wide builds, in gh-80480. What remains is the request to say that 'w' holds Py_UCS4, so the new row names that C type, which is also what the "C Type" column of the table in Doc/library/array.rst gives for 'w'. Add a test asserting that the table lists exactly the supported type codes and that the minimum size it gives for each of them is one the implementation really meets. --- Lib/test/test_array.py | 19 +++++++++++++++++++ ...-09-24-01-20-36.gh-issue-142083.WOlkvr.rst | 3 +++ Modules/arraymodule.c | 1 + 3 files changed, 23 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2026-09-24-01-20-36.gh-issue-142083.WOlkvr.rst diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index ba9c25c835bc39..382b14ad9a1788 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -12,6 +12,7 @@ import weakref import pickle import operator +import re import struct import sys @@ -110,6 +111,24 @@ def test_typecodes(self): self.assertIsInstance(typecode, str) self.assertGreaterEqual(len(typecode), 1) + @support.cpython_only + @support.requires_docstrings + def test_typecodes_documented(self): + # The type code table in the array.array docstring must list every + # supported type code, and nothing else, and the minimum size it + # gives for each of them must be one the implementation meets. + row = re.compile(r"^ {4}('\w+') +\S.*? +(\d+)(?: \(see note\))?$") + documented = {} + for line in array.array.__doc__.splitlines(): + match = row.match(line) + if match is not None: + documented[match.group(1).strip("'")] = int(match.group(2)) + self.assertEqual(sorted(documented), sorted(array.typecodes)) + for typecode, minimum_size in documented.items(): + with self.subTest(typecode=typecode): + self.assertGreaterEqual(array.array(typecode).itemsize, + minimum_size) + # Machine format codes. # diff --git a/Misc/NEWS.d/next/Documentation/2026-09-24-01-20-36.gh-issue-142083.WOlkvr.rst b/Misc/NEWS.d/next/Documentation/2026-09-24-01-20-36.gh-issue-142083.WOlkvr.rst new file mode 100644 index 00000000000000..d8f20396b4556a --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2026-09-24-01-20-36.gh-issue-142083.WOlkvr.rst @@ -0,0 +1,3 @@ +Document the ``'w'`` type code in the :class:`array.array` docstring, so +that it lists the same type codes as :data:`array.typecodes` and the +:mod:`array` module documentation. diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index ef492d143d5644..64dacd1b8f1f61 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -3109,6 +3109,7 @@ The following type codes are defined:\n\ Type code C Type Minimum size in bytes\n\ 'b' signed integer 1\n\ 'B' unsigned integer 1\n\ + 'w' Py_UCS4 4\n\ 'h' signed integer 2\n\ 'H' unsigned integer 2\n\ 'i' signed integer 2\n\ From 0cdf4be666fb6fd1ac4b8fd47959aad31bbea61d Mon Sep 17 00:00:00 2001 From: Dmitry Voropaev Date: Thu, 1 Oct 2026 19:49:41 +0300 Subject: [PATCH 2/2] Drop the quotes from the capture group in the type code regex --- Lib/test/test_array.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 382b14ad9a1788..580966589fdd6b 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -117,12 +117,13 @@ def test_typecodes_documented(self): # The type code table in the array.array docstring must list every # supported type code, and nothing else, and the minimum size it # gives for each of them must be one the implementation meets. - row = re.compile(r"^ {4}('\w+') +\S.*? +(\d+)(?: \(see note\))?$") + row = re.compile(r"^ {4}'(\w+)' +\S.*? +(\d+)(?: \(see note\))?$") documented = {} for line in array.array.__doc__.splitlines(): match = row.match(line) if match is not None: - documented[match.group(1).strip("'")] = int(match.group(2)) + documented[match.group(1)] = int(match.group(2)) + self.assertEqual(sorted(documented), sorted(array.typecodes)) for typecode, minimum_size in documented.items(): with self.subTest(typecode=typecode):