8000 [3.13] gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-depre… · python/cpython@a4c7eb5 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4c7eb5

Browse files
[3.13] gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. (GH-122281) (GH-122440)
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 (cherry picked from commit 3833d27) Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent a2c36dd commit a4c7eb5

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
@@ -2621,6 +2621,15 @@ Arrays and pointers
26212621
Array subclass constructors accept positional arguments, used to
26222622
initialize the elements in order.
26232623

2624+
.. function:: ARRAY(type, length)
2625+
2626+
Create an array.
2627+
Equivalent to ``type * length``, where *type* is a
2628+
:mod:`ctypes` data type and *length* an integer.
2629+
2630+
This function is :term:`soft deprecated` in favor of multiplication.
2631+
There are no plans to remove it.
2632+
26242633

26252634
.. class:: _Pointer
26262635

Doc/whatsnew/3.13.rst

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

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

14891489
* :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
@@ -314,8 +314,6 @@ def SetPointerType(pointer, cls):
314314
del _pointer_type_cache[id(pointer)]
315315

316316
def ARRAY(typ, len):
317-
import warnings
318-
warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
319317
return typ * len
320318

321319
################################################################

Lib/test/test_ctypes/test_arrays.py

Lines changed: 1 addition & 13 d 10000 eletions
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)
0