Skip to content

Commit 852c5ef

Browse files
committed
pythongh-80480 Deprecate array's 'u' type code
1 parent 489be0d commit 852c5ef

File tree

7 files changed

+32
-5
lines changed

7 files changed

+32
-5
lines changed

Doc/library/array.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Notes:
5555
``Py_UNICODE``. This change doesn't affect its behavior because
5656
``Py_UNICODE`` is alias of ``wchar_t`` since Python 3.3.
5757

58-
.. deprecated-removed:: 3.3 4.0
58+
.. deprecated-removed:: 3.3 3.14
5959

6060

6161
The actual representation of values is determined by the machine architecture

Doc/whatsnew/3.12.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ Pending Removal in Python 3.14
205205

206206
(Contributed by Jason R. Coombs and Hugo van Kemenade in :gh:`93963`.)
207207

208+
APIs:
209+
208210
* Creating :c:data:`immutable types <Py_TPFLAGS_IMMUTABLETYPE>` with mutable
209-
bases using the C API.
211+
bases using the C API (:gh:`95388`)
212+
* :mod:`array`'s ``'u'`` format code (:gh:`57281`)
210213

211214

212215
Pending Removal in Future Versions

Lib/test/test_array.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
import operator
1414
import struct
1515
import sys
16+
import warnings
1617

1718
import array
1819
from array import _array_reconstructor as array_reconstructor
1920

20-
sizeof_wchar = array.array('u').itemsize
21+
with warnings.catch_warnings():
22+
warnings.simplefilter('ignore', DeprecationWarning)
23+
sizeof_wchar = array.array('u').itemsize
2124

2225

2326
class ArraySubclass(array.array):
@@ -93,8 +96,16 @@ def test_empty(self):
9396
UTF32_LE = 20
9497
UTF32_BE = 21
9598

99+
96100
class ArrayReconstructorTest(unittest.TestCase):
97101

102+
def setUp(self):
103+
warnings.filterwarnings(
104+
"ignore",
105+
message="The 'u' type code is deprecated and "
106+
"will be removed in Python 3.14",
107+
category=DeprecationWarning)
108+
98109
def test_error(self):
99110
self.assertRaises(TypeError, array_reconstructor,
100111
"", "b", 0, b"")

Lib/test/test_buffer.py

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import sys, array, io, os
2424
from decimal import Decimal
2525
from fractions import Fraction
26+
from test.support import warnings_helper
2627

2728
try:
2829
from _testbuffer import *
@@ -3174,6 +3175,7 @@ def cmptest(testcase, a, b, m, singleitem):
31743175
self.assertEqual(m.tobytes(), a.tobytes())
31753176
cmptest(self, a, b, m, singleitem)
31763177

3178+
@warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480
31773179
def test_memoryview_compare_special_cases(self):
31783180

31793181
a = array.array('L', [1, 2, 3])

Lib/test/test_csv.py

+1
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,7 @@ def test_float_write(self):
880880
fileobj.seek(0)
881881
self.assertEqual(fileobj.read(), expected)
882882

883+
@warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480
883884
def test_char_write(self):
884885
import array, string
885886
a = array.array('u', string.ascii_letters)

Lib/test/test_re.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from test.support import (gc_collect, bigmemtest, _2G,
22
cpython_only, captured_stdout,
33
check_disallow_instantiation, is_emscripten, is_wasi,
4-
SHORT_TIMEOUT)
4+
warnings_helper, SHORT_TIMEOUT)
55
import locale
66
import re
77
import string
@@ -1517,10 +1517,11 @@ def test_bug_6561(self):
15171517
for x in not_decimal_digits:
15181518
self.assertIsNone(re.match(r'^\d$', x))
15191519

1520+
@warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480
15201521
def test_empty_array(self):
15211522
# SF buf 1647541
15221523
import array
1523-
for typecode in 'bBuhHiIlLfd':
1524+
for typecode in 'bBhuHiIlLfd':
15241525
a = array.array(typecode)
15251526
self.assertIsNone(re.compile(b"bla").match(a))
15261527
self.assertEqual(re.compile(b"").match(a).groups(), ())

Modules/arraymodule.c

+9
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,15 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
26202620
if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial))
26212621
return NULL;
26222622

2623+
if (c == 'u') {
2624+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2625+
"The 'u' type code is deprecated and "
2626+
"will be removed in Python 3.14",
2627+
1)) {
2628+
return NULL;
2629+
}
2630+
}
2631+
26232632
if (PySys_Audit("array.__new__", "CO",
26242633
c, initial ? initial : Py_None) < 0) {
26252634
return NULL;

0 commit comments

Comments
 (0)