diff --git a/Doc/library/array.rst b/Doc/library/array.rst index 975670cc81a2024..e282646f8fb8966 100644 --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -55,7 +55,7 @@ Notes: ``Py_UNICODE``. This change doesn't affect its behavior because ``Py_UNICODE`` is alias of ``wchar_t`` since Python 3.3. - .. deprecated-removed:: 3.3 4.0 + .. deprecated-removed:: 3.3 3.14 The actual representation of values is determined by the machine architecture diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index ddf9e1f6a59b471..d801002360e45ca 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -205,8 +205,11 @@ Pending Removal in Python 3.14 (Contributed by Jason R. Coombs and Hugo van Kemenade in :gh:`93963`.) +APIs: + * Creating :c:data:`immutable types ` with mutable - bases using the C API. + bases using the C API (:gh:`95388`) +* :mod:`array`'s ``'u'`` format code (:gh:`57281`) Pending Removal in Future Versions diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 5b2c107a6044bdf..d637baaf619e63d 100755 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -13,11 +13,14 @@ import operator import struct import sys +import warnings import array from array import _array_reconstructor as array_reconstructor -sizeof_wchar = array.array('u').itemsize +with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + sizeof_wchar = array.array('u').itemsize class ArraySubclass(array.array): @@ -93,8 +96,16 @@ def test_empty(self): UTF32_LE = 20 UTF32_BE = 21 + class ArrayReconstructorTest(unittest.TestCase): + def setUp(self): + warnings.filterwarnings( + "ignore", + message="The 'u' type code is deprecated and " + "will be removed in Python 3.14", + category=DeprecationWarning) + def test_error(self): self.assertRaises(TypeError, array_reconstructor, "", "b", 0, b"") diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py index 468c6ea9def9234..194067a8d395289 100644 --- a/Lib/test/test_buffer.py +++ b/Lib/test/test_buffer.py @@ -23,6 +23,7 @@ import sys, array, io, os from decimal import Decimal from fractions import Fraction +from test.support import warnings_helper try: from _testbuffer import * @@ -3174,6 +3175,7 @@ def cmptest(testcase, a, b, m, singleitem): self.assertEqual(m.tobytes(), a.tobytes()) cmptest(self, a, b, m, singleitem) + @warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480 array('u') def test_memoryview_compare_special_cases(self): a = array.array('L', [1, 2, 3]) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 95a19dd46cb4ffa..07f65b6281c194d 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -880,6 +880,7 @@ def test_float_write(self): fileobj.seek(0) self.assertEqual(fileobj.read(), expected) + @warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480 array('u') def test_char_write(self): import array, string a = array.array('u', string.ascii_letters) diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 3f0f84ea8cee6fa..a5d0d896b756fee 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1,7 +1,7 @@ from test.support import (gc_collect, bigmemtest, _2G, cpython_only, captured_stdout, check_disallow_instantiation, is_emscripten, is_wasi, - SHORT_TIMEOUT) + warnings_helper, SHORT_TIMEOUT) import locale import re import string @@ -1517,10 +1517,11 @@ def test_bug_6561(self): for x in not_decimal_digits: self.assertIsNone(re.match(r'^\d$', x)) + @warnings_helper.ignore_warnings(category=DeprecationWarning) # gh-80480 array('u') def test_empty_array(self): # SF buf 1647541 import array - for typecode in 'bBuhHiIlLfd': + for typecode in 'bBhuHiIlLfd': a = array.array(typecode) self.assertIsNone(re.compile(b"bla").match(a)) self.assertEqual(re.compile(b"").match(a).groups(), ()) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 924fbf29bfb8895..147d607fb226f04 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2620,6 +2620,15 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial)) return NULL; + if (c == 'u') { + if (PyErr_WarnEx(PyExc_DeprecationWarning, + "The 'u' type code is deprecated and " + "will be removed in Python 3.14", + 1)) { + return NULL; + } + } + if (PySys_Audit("array.__new__", "CO", c, initial ? initial : Py_None) < 0) { return NULL;