Skip to content

Commit 3ce3543

Browse files
authored
[3.14] gh-142083: Document the 'w' type code in the array.array docstring (#158040) (#158575) (#159257)
[3.15] gh-142083: Document the 'w' type code in the array.array docstring (#158040) (#158575) 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. Co-authored-by: Dmitry Voropaev <dy.voropaev@gmail.com> (cherry picked from commit ab01d18) (cherry picked from commit c5cc92c)
1 parent d0888f9 commit 3ce3543

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎Lib/test/test_array.py‎

Lines changed: 22 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
@@ -90,6 +91,27 @@ def test_empty(self):
9091
a += a
9192
self.assertEqual(len(a), 0)
9293

94+
@support.cpython_only
95+
@support.requires_docstrings
96+
def test_typecodes_documented(self):
97+
# The type code table in the array.array docstring must list every
98+
# supported type code, and nothing else, and the minimum size it
99+
# gives for each of them must be one the implementation meets.
100+
row = re.compile(r"^ {4}'(\w+)' +\S.*? +(\d+)(?: \(see note\))?$")
101+
documented = {}
102+
for line in array.array.__doc__.splitlines():
103+
match = row.match(line)
104+
if match is not None:
105+
documented[match.group(1)] = int(match.group(2))
106+
107+
self.assertEqual(sorted(documented), sorted(array.typecodes))
108+
for typecode, minimum_size in documented.items():
109+
with self.subTest(typecode=typecode):
110+
with warnings.catch_warnings():
111+
warnings.simplefilter('ignore', DeprecationWarning)
112+
self.assertGreaterEqual(array.array(typecode).itemsize,
113+
minimum_size)
114+
93115

94116
# Machine format codes.
95117
#
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
@@ -2995,6 +2995,7 @@ The following type codes are defined:\n\
29952995
'b' signed integer 1\n\
29962996
'B' unsigned integer 1\n\
29972997
'u' Unicode character 2 (see note)\n\
2998+
'w' Py_UCS4 4\n\
29982999
'h' signed integer 2\n\
29993000
'H' unsigned integer 2\n\
30003001
'i' signed integer 2\n\

0 commit comments

Comments
 (0)