Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc87948

Browse files
authored
gh-80480: Emit DeprecationWarning for array's 'u' type code (#95760)
1 parent3a314f7 commitcc87948

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

‎Doc/library/array.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Notes:
5757
``Py_UNICODE``. This change doesn't affect its behavior because
5858
``Py_UNICODE`` is alias of ``wchar_t`` since Python 3.3.
5959

60-
..deprecated-removed::3.34.0
60+
..deprecated-removed::3.33.16
6161
Please migrate to ``'w'`` typecode.
6262

6363

‎Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ Deprecated
134134
They will be removed in Python 3.15.
135135
(Contributed by Victor Stinner in:gh:`105096`.)
136136

137+
*:mod:`array`'s ``'u'`` format code, deprecated in docs since Python 3.3,
138+
emits:exc:`DeprecationWarning` since 3.13
139+
and will be removed in Python 3.16.
140+
Use the ``'w'`` format code instead.
141+
(contributed by Hugo van Kemenade in:gh:`80480`)
137142

138143
Removed
139144
=======

‎Lib/test/test_array.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
importoperator
1414
importstruct
1515
importsys
16+
importwarnings
1617

1718
importarray
1819
fromarrayimport_array_reconstructorasarray_reconstructor
1920

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

2225

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

99+
96100
classArrayReconstructorTest(unittest.TestCase):
97101

102+
defsetUp(self):
103+
warnings.filterwarnings(
104+
"ignore",
105+
message="The 'u' type code is deprecated and "
106+
"will be removed in Python 3.16",
107+
category=DeprecationWarning)
108+
98109
deftest_error(self):
99110
self.assertRaises(TypeError,array_reconstructor,
100111
"","b",0,b"")
@@ -1208,10 +1219,16 @@ def test_issue17223(self):
12081219
self.assertRaises(ValueError,a.tounicode)
12091220
self.assertRaises(ValueError,str,a)
12101221

1222+
deftest_typecode_u_deprecation(self):
1223+
withself.assertWarns(DeprecationWarning):
1224+
array.array("u")
1225+
1226+
12111227
classUCS4Test(UnicodeTest):
12121228
typecode='w'
12131229
minitemsize=4
12141230

1231+
12151232
classNumberTest(BaseTest):
12161233

12171234
deftest_extslice(self):

‎Lib/test/test_buffer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
importsys,array,io,os
2525
fromdecimalimportDecimal
2626
fromfractionsimportFraction
27+
fromtest.supportimportwarnings_helper
2728

2829
try:
2930
from_testbufferimport*
@@ -3217,12 +3218,6 @@ def test_memoryview_compare_special_cases(self):
32173218
nd[0]= (-1,float('nan'))
32183219
self.assertNotEqual(memoryview(nd),nd)
32193220

3220-
# Depends on issue #15625: the struct module does not understand 'u'.
3221-
a=array.array('u','xyz')
3222-
v=memoryview(a)
3223-
self.assertNotEqual(a,v)
3224-
self.assertNotEqual(v,a)
3225-
32263221
# Some ctypes format strings are unknown to the struct module.
32273222
ifctypes:
32283223
# format: "T{>l:x:>l:y:}"
@@ -3236,6 +3231,15 @@ class BEPoint(ctypes.BigEndianStructure):
32363231
self.assertNotEqual(point,a)
32373232
self.assertRaises(NotImplementedError,a.tolist)
32383233

3234+
@warnings_helper.ignore_warnings(category=DeprecationWarning)# gh-80480 array('u')
3235+
deftest_memoryview_compare_special_cases_deprecated_u_type_code(self):
3236+
3237+
# Depends on issue #15625: the struct module does not understand 'u'.
3238+
a=array.array('u','xyz')
3239+
v=memoryview(a)
3240+
self.assertNotEqual(a,v)
3241+
self.assertNotEqual(v,a)
3242+
32393243
deftest_memoryview_compare_ndim_zero(self):
32403244

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

‎Lib/test/test_re.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fromtest.supportimport (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
importlocale
66
importre
77
importstring
@@ -1522,10 +1522,11 @@ def test_bug_6561(self):
15221522
forxinnot_decimal_digits:
15231523
self.assertIsNone(re.match(r'^\d$',x))
15241524

1525+
@warnings_helper.ignore_warnings(category=DeprecationWarning)# gh-80480 array('u')
15251526
deftest_empty_array(self):
15261527
# SF buf 1647541
15271528
importarray
1528-
fortypecodein'bBuhHiIlLfd':
1529+
fortypecodein'bBhuwHiIlLfd':
15291530
a=array.array(typecode)
15301531
self.assertIsNone(re.compile(b"bla").match(a))
15311532
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+
Emit:exc:`DeprecationWarning` for:mod:`array`'s ``'u'`` type code,
2+
deprecated in docs since Python 3.3.

‎Modules/arraymodule.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2679,6 +2679,15 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
26792679
returnNULL;
26802680
}
26812681

2682+
if (c=='u') {
2683+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
2684+
"The 'u' type code is deprecated and "
2685+
"will be removed in Python 3.16",
2686+
1)) {
2687+
returnNULL;
2688+
}
2689+
}
2690+
26822691
boolis_unicode=c=='u'||c=='w';
26832692

26842693
if (initial&& !is_unicode) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp