8000 gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. by encukou · Pull Request #122281 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. #122281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,15 @@ Arrays and pointers
Array subclass constructors accept positional arguments, used to
initialize the elements in order.

.. function:: ARRAY(type, length)

Create an array.
Equivalent to ``type * length``, where *type* is a
:mod:`ctypes` data type and *length* an integer.

This function is :term:`soft deprecated` in favor of multiplication.
There are no plans to remove it.


.. class:: _Pointer

Expand Down
4 changes: 2 additions & 2 deletions Doc/whatsnew/3.13.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1494,8 +1494,8 @@ New Deprecations
(Contributed by Hugo van Kemenade in :gh:`80480`.)

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

* :mod:`decimal`: Deprecate non-standard format specifier "N" for
Expand Down
2 changes: 0 additions & 2 deletions Lib/ctypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,6 @@ def SetPointerType(pointer, cls):
del _pointer_type_cache[id(pointer)]

def ARRAY(typ, len):
import warnings
warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
return typ * len

################################################################
Expand Down
14 changes: 1 addition & 13 deletions Lib/test/test_ctypes/test_arrays.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ctypes
import sys
import unittest
import warnings
from ctypes import (Structure, Array, sizeof, addressof,
from ctypes import (Structure, Array, ARRAY, sizeof, addressof,
create_string_buffer, create_unicode_buffer,
c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulonglong, c_float, c_double, c_longdouble)
Expand All @@ -17,13 +16,6 @@
c_long, c_ulonglong, c_float, c_double, c_longdouble


def ARRAY(*args):
# ignore DeprecationWarning in tests
with warnings.catch_warnings():
warnings.simplefilter('ignore', DeprecationWarning)
return ctypes.ARRAY(*args)


class ArrayTestCase(unittest.TestCase):
def test_inheritance_hierarchy(self):
self.assertEqual(Array.mro(), [Array, _CData, object])
Expand Down Expand Up @@ -275,10 +267,6 @@ def test_bpo36504_signed_int_overflow(self):
def test_large_array(self, size):
c_char * size

def test_deprecation(self):
with self.assertWarns(DeprecationWarning):
CharArray = ctypes.ARRAY(c_char, 3)


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`ctypes.ARRAY` is now :term:`soft deprecated`: it no longer emits deprecation
warnings and is not scheduled for removal.
Loading
0