Skip to content

Commit 3833d27

Browse files
authored
gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. (GH-122281)
Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. Partially reverts 2211454
1 parent 11ad731 commit 3833d27

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

Doc/library/ctypes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2688,6 +2688,15 @@ Arrays and pointers
26882688
Array subclass constructors accept positional arguments, used to
26892689
initialize the elements in order.
26902690

2691+
.. function:: ARRAY(type, length)
2692+
2693+
Create an array.
2694+
Equivalent to ``type * length``, where *type* is a
2695+
:mod:`ctypes` data type and *length* an integer.
2696+
2697+
This function is :term:`soft deprecated` in favor of multiplication.
2698+
There are no plans to remove it.
2699+
26912700

26922701
.. class:: _Pointer
26932702

Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,8 @@ New Deprecations
14941494
(Contributed by Hugo van Kemenade in :gh:`80480`.)
14951495

14961496
* :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType`
1497-
and :func:`!ctypes.ARRAY` functions.
1498-
Replace ``ctypes.ARRAY(item_type, size)`` with ``item_type * size``.
1497+
function. :term:`Soft-deprecate <soft deprecated>` the :func:`ctypes.ARRAY`
1498+
function in favor of multiplication.
14991499
(Contributed by Victor Stinner in :gh:`105733`.)
15001500

15011501
* :mod:`decimal`: Deprecate non-standard format specifier "N" for

Lib/ctypes/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ def SetPointerType(pointer, cls):
324324
del _pointer_type_cache[id(pointer)]
325325

326326
def ARRAY(typ, len):
327-
import warnings
328-
warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
329327
return typ * len
330328

331329
################################################################

Lib/test/test_ctypes/test_arrays.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import ctypes
22
import sys
33
import unittest
4-
import warnings
5-
from ctypes import (Structure, Array, sizeof, addressof,
4+
from ctypes import (Structure, Array, ARRAY, sizeof, addressof,
65
create_string_buffer, create_unicode_buffer,
76
c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
87
c_long, c_ulonglong, c_float, c_double, c_longdouble)
@@ -17,13 +16,6 @@
1716
c_long, c_ulonglong, c_float, c_double, c_longdouble
1817

1918

20-
def ARRAY(*args):
21-
# ignore DeprecationWarning in tests
22-
with warnings.catch_warnings():
23-
warnings.simplefilter('ignore', DeprecationWarning)
24-
return ctypes.ARRAY(*args)
25-
26-
2719
class ArrayTestCase(unittest.TestCase):
2820
def test_inheritance_hierarchy(self):
2921
self.assertEqual(Array.mro(), [Array, _CData, object])
@@ -275,10 +267,6 @@ def test_bpo36504_signed_int_overflow(self):
275267
def test_large_array(self, size):
276268
c_char * size
277269

278-
def test_deprecation(self):
279-
with self.assertWarns(DeprecationWarning):
280-
CharArray = ctypes.ARRAY(c_char, 3)
281-
282270

283271
if __name__ == '__main__':
284272
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`ctypes.ARRAY` is now :term:`soft deprecated`: it no longer emits deprecation
2+
warnings and is not scheduled for removal.

0 commit comments

Comments
 (0)