Skip to content

Commit 2009a2d

Browse files
committed
gh-80480: remove deprecated 'u' type code (array)
1 parent 4ae1a26 commit 2009a2d

6 files changed

Lines changed: 56 additions & 227 deletions

File tree

Doc/whatsnew/3.16.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ annotationlib
114114
Use :meth:`annotationlib.ForwardRef.evaluate`
115115
or :func:`typing.evaluate_forward_ref` instead.
116116

117+
array
118+
-----
119+
120+
* The ``'u'`` format code (:c:type:`wchar_t`) which has been deprecated in
121+
documentation since Python 3.3 and at runtime since Python 3.13.
122+
117123
sysconfig
118124
---------
119125

Lib/test/test_array.py

Lines changed: 11 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,10 @@
1414
import operator
1515
import struct
1616
import sys
17-
import warnings
1817

1918
import array
2019
from array import _array_reconstructor as array_reconstructor
2120

22-
with warnings.catch_warnings():
23-
warnings.simplefilter('ignore', DeprecationWarning)
24-
sizeof_wchar = array.array('u').itemsize
25-
2621

2722
class ArraySubclass(array.array):
2823
pass
@@ -32,7 +27,7 @@ def __init__(self, typecode, newarg=None):
3227
array.array.__init__(self)
3328

3429
typecodes = (
35-
'u', 'w', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L',
30+
'w', 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L',
3631
'f', 'd', 'q', 'Q', 'e', 'Zf', 'Zd')
3732

3833

@@ -135,14 +130,6 @@ def test_typecodes(self):
135130

136131
class ArrayReconstructorTest(unittest.TestCase):
137132

138-
def setUp(self):
139-
self.enterContext(warnings.catch_warnings())
140-
warnings.filterwarnings(
141-
"ignore",
142-
message="The 'u' type code is deprecated and "
143-
"will be removed in Python 3.16",
144-
category=DeprecationWarning)
145-
146133
def test_error(self):
147134
self.assertRaises(TypeError, array_reconstructor,
148135
"", "b", 0, b"")
@@ -242,12 +229,11 @@ def test_unicode(self):
242229
)
243230
for testcase in testcases:
244231
mformat_code, encoding = testcase
245-
for c in 'uw':
246-
a = array.array(c, teststr)
247-
b = array_reconstructor(
248-
array.array, c, mformat_code, teststr.encode(encoding))
249-
self.assertEqual(a, b,
250-
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
232+
a = array.array('w', teststr)
233+
b = array_reconstructor(
234+
array.array, 'w', mformat_code, teststr.encode(encoding))
235+
self.assertEqual(a, b,
236+
msg="{0!r} != {1!r}; testcase={2!r}".format(a, b, testcase))
251237

252238

253239
class BaseTest:
@@ -259,14 +245,6 @@ class BaseTest:
259245
# outside: An entry that is not in example
260246
# minitemsize: the minimum guaranteed itemsize
261247

262-
def setUp(self):
263-
self.enterContext(warnings.catch_warnings())
264-
warnings.filterwarnings(
265-
"ignore",
266-
message="The 'u' type code is deprecated and "
267-
"will be removed in Python 3.16",
268-
category=DeprecationWarning)
269-
270248
def assertEntryEqual(self, entry1, entry2):
271249
self.assertEqual(entry1, entry2)
272250

@@ -299,7 +277,7 @@ def test_buffer_info(self):
299277
self.assertEqual(bi[1], len(a))
300278

301279
def test_byteswap(self):
302-
if self.typecode in ('u', 'w'):
280+
if self.typecode == 'w':
303281
example = '\U00100100'
304282
else:
305283
example = self.example
@@ -1167,7 +1145,7 @@ def test_buffer(self):
11671145
self.assertEqual(m.tobytes(), expected)
11681146
self.assertRaises(BufferError, a.frombytes, a.tobytes())
11691147
self.assertEqual(m.tobytes(), expected)
1170-
if self.typecode in ('u', 'w'):
1148+
if self.typecode == 'w':
11711149
self.assertRaises(BufferError, a.fromunicode, a.tounicode())
11721150
self.assertEqual(m.tobytes(), expected)
11731151
self.assertRaises(BufferError, operator.imul, a, 2)
@@ -1223,7 +1201,7 @@ def test_sizeof_without_buffer(self):
12231201
support.check_sizeof(self, a, basesize)
12241202

12251203
def test_initialize_with_unicode(self):
1226-
if self.typecode not in ('u', 'w'):
1204+
if self.typecode != 'w':
12271205
with self.assertRaises(TypeError) as cm:
12281206
a = array.array(self.typecode, 'foo')
12291207
self.assertIn("cannot use a str", str(cm.exception))
@@ -1232,7 +1210,6 @@ def test_initialize_with_unicode(self):
12321210
self.assertIn("cannot use a unicode array", str(cm.exception))
12331211
else:
12341212
a = array.array(self.typecode, "foo")
1235-
a = array.array(self.typecode, array.array('u', 'foo'))
12361213
a = array.array(self.typecode, array.array('w', 'foo'))
12371214

12381215
@support.cpython_only
@@ -1258,12 +1235,12 @@ def test_setitem(self):
12581235
self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2])
12591236

12601237
class UnicodeTest(StringTest, unittest.TestCase):
1261-
typecode = 'u'
1238+
typecode = 'w'
12621239
example = '\x01\u263a\x00\ufeff'
12631240
smallerexample = '\x01\u263a\x00\ufefe'
12641241
biggerexample = '\x01\u263a\x01\ufeff'
12651242
outside = str('\x33')
1266-
minitemsize = sizeof_wchar
1243+
minitemsize = 4
12671244

12681245
def test_unicode(self):
12691246
self.assertRaises(TypeError, array.array, 'b', 'foo')
@@ -1285,36 +1262,6 @@ def test_unicode(self):
12851262

12861263
self.assertRaises(TypeError, a.fromunicode)
12871264

1288-
def test_issue17223(self):
1289-
if self.typecode == 'u' and sizeof_wchar == 2:
1290-
# PyUnicode_FromUnicode() cannot fail with 16-bit wchar_t
1291-
self.skipTest("specific to 32-bit wchar_t")
1292-
1293-
# this used to crash
1294-
# U+FFFFFFFF is an invalid code point in Unicode 6.0
1295-
invalid_str = b'\xff\xff\xff\xff'
1296-
1297-
a = array.array(self.typecode, invalid_str)
1298-
self.assertRaises(ValueError, a.tounicode)
1299-
self.assertRaises(ValueError, str, a)
1300-
1301-
def test_typecode_u_deprecation(self):
1302-
with self.assertWarns(DeprecationWarning):
1303-
array.array("u")
1304-
1305-
def test_empty_string_mem_leak_gh140474(self):
1306-
with warnings.catch_warnings():
1307-
warnings.simplefilter('ignore', DeprecationWarning)
1308-
for _ in range(1000):
1309-
a = array.array('u', '')
1310-
self.assertEqual(len(a), 0)
1311-
self.assertEqual(a.typecode, 'u')
1312-
1313-
1314-
class UCS4Test(UnicodeTest):
1315-
typecode = 'w'
1316-
minitemsize = 4
1317-
13181265

13191266
class NumberTest(BaseTest):
13201267

Lib/test/test_buffer.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import sys, array, io, os
2525
from decimal import Decimal
2626
from fractions import Fraction
27-
from test.support import warnings_helper
2827

2928
try:
3029
from _testbuffer import *
@@ -3261,15 +3260,6 @@ class BEPoint(ctypes.BigEndianStructure):
32613260
self.assertNotEqual(point, a)
32623261
self.assertRaises(NotImplementedError, a.tolist)
32633262

3264-
@warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480 array('u')
3265-
def test_memoryview_compare_special_cases_deprecated_u_type_code(self):
3266-
3267-
# Depends on issue #15625: the struct module does not understand 'u'.
3268-
a = array.array('u', 'xyz')
3269-
v = memoryview(a)
3270-
self.assertNotEqual(a, v)
3271-
self.assertNotEqual(v, a)
3272-
32733263
def test_memoryview_compare_ndim_zero(self):
32743264

32753265
nd1 = ndarray(1729, shape=[], format='@L')

Lib/test/test_re.py

Lines changed: 2 additions & 3 deletions
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, linked_to_musl,
4-
warnings_helper, SHORT_TIMEOUT, Stopwatch, requires_resource)
4+
SHORT_TIMEOUT, Stopwatch, requires_resource)
55
import locale
66
import re
77
import string
@@ -1780,11 +1780,10 @@ def test_bug_6561(self):
17801780
for x in not_decimal_digits:
17811781
self.assertIsNone(re.match(r'^\d$', x))
17821782

1783-
@warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480 array('u')
17841783
def test_empty_array(self):
17851784
# SF buf 1647541
17861785
import array
1787-
for typecode in 'bBhuwHiIlLfd':
1786+
for typecode in 'bBhwHiIlLfd':
17881787
a = array.array(typecode)
17891788
self.assertIsNone(re.compile(b"bla").match(a))
17901789
self.assertEqual(re.compile(b"").match(a).groups(), ())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Remove deprecated ``'u'`` type code (:c:type:`wchar_t`) for the :mod:`array`
2+
module.

0 commit comments

Comments
 (0)