Skip to content

Commit 728b815

Browse files
v0ropaevvstinner
authored andcommitted
gh-142083: Document the 'w' type code in the array.array docstring (#158040)
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. (cherry picked from commit ab01d18)
1 parent 021f634 commit 728b815

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎Lib/test/test_array.py‎

Lines changed: 20 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
import warnings
@@ -117,6 +118,25 @@ def test_typecodes(self):
117118
self.assertIsInstance(typecode, str)
118119
self.assertGreaterEqual(len(typecode), 1)
119120

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

121141
# Machine format codes.
122142
#
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
@@ -3200,6 +3200,7 @@ The following type codes are defined:\n\
32003200
'b' signed integer 1\n\
32013201
'B' unsigned integer 1\n\
32023202
'u' Unicode character 2 (see note)\n\
3203+
'w' Py_UCS4 4\n\
32033204
'h' signed integer 2\n\
32043205
'H' unsigned integer 2\n\
32053206
'i' signed integer 2\n\

0 commit comments

Comments
 (0)