Skip to content

Commit 7441b57

Browse files
committed
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.
1 parent 6893326 commit 7441b57

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎Lib/test/test_array.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import weakref
1313
import pickle
1414
import operator
15+
import re
1516
import struct
1617
import sys
1718

@@ -110,6 +111,24 @@ def test_typecodes(self):
110111
self.assertIsInstance(typecode, str)
111112
self.assertGreaterEqual(len(typecode), 1)
112113

114+
@support.cpython_only
115+
@support.requires_docstrings
116+
def test_typecodes_documented(self):
117+
# The type code table in the array.array docstring must list every
118+
# supported type code, and nothing else, and the minimum size it
119+
# gives for each of them must be one the implementation meets.
120+
row = re.compile(r"^ {4}('\w+') +\S.*? +(\d+)(?: \(see note\))?$")
121+
documented = {}
122+
for line in array.array.__doc__.splitlines():
123+
match = row.match(line)
124+
if match is not None:
125+
documented[match.group(1).strip("'")] = int(match.group(2))
126+
self.assertEqual(sorted(documented), sorted(array.typecodes))
127+
for typecode, minimum_size in documented.items():
128+
with self.subTest(typecode=typecode):
129+
self.assertGreaterEqual(array.array(typecode).itemsize,
130+
minimum_size)
131+
113132

114133
# Machine format codes.
115134
#
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Document the ``'w'`` type code in the :class:`array.array` docstring, so
2+
that it lists the same type codes as :data:`array.typecodes` and the
3+
:mod:`array` module documentation.

‎Modules/arraymodule.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,6 +3109,7 @@ The following type codes are defined:\n\
31093109
Type code C Type Minimum size in bytes\n\
31103110
'b' signed integer 1\n\
31113111
'B' unsigned integer 1\n\
3112+
'w' Py_UCS4 4\n\
31123113
'h' signed integer 2\n\
31133114
'H' unsigned integer 2\n\
31143115
'i' signed integer 2\n\

0 commit comments

Comments
 (0)