mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
gh-105733: Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it. (GH-122281)
Soft-deprecate ctypes.ARRAY, rather than hard-deprecating it.
Partially reverts 2211454fe2
This commit is contained in:
parent
11ad731f4f
commit
3833d27f98
5 changed files with 14 additions and 17 deletions
|
@ -2688,6 +2688,15 @@ Arrays and pointers
|
||||||
Array subclass constructors accept positional arguments, used to
|
Array subclass constructors accept positional arguments, used to
|
||||||
initialize the elements in order.
|
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
|
.. class:: _Pointer
|
||||||
|
|
||||||
|
|
|
@ -1494,8 +1494,8 @@ New Deprecations
|
||||||
(Contributed by Hugo van Kemenade in :gh:`80480`.)
|
(Contributed by Hugo van Kemenade in :gh:`80480`.)
|
||||||
|
|
||||||
* :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType`
|
* :mod:`ctypes`: Deprecate undocumented :func:`!ctypes.SetPointerType`
|
||||||
and :func:`!ctypes.ARRAY` functions.
|
function. :term:`Soft-deprecate <soft deprecated>` the :func:`ctypes.ARRAY`
|
||||||
Replace ``ctypes.ARRAY(item_type, size)`` with ``item_type * size``.
|
function in favor of multiplication.
|
||||||
(Contributed by Victor Stinner in :gh:`105733`.)
|
(Contributed by Victor Stinner in :gh:`105733`.)
|
||||||
|
|
||||||
* :mod:`decimal`: Deprecate non-standard format specifier "N" for
|
* :mod:`decimal`: Deprecate non-standard format specifier "N" for
|
||||||
|
|
|
@ -324,8 +324,6 @@ def SetPointerType(pointer, cls):
|
||||||
del _pointer_type_cache[id(pointer)]
|
del _pointer_type_cache[id(pointer)]
|
||||||
|
|
||||||
def ARRAY(typ, len):
|
def ARRAY(typ, len):
|
||||||
import warnings
|
|
||||||
warnings._deprecated("ctypes.ARRAY", remove=(3, 15))
|
|
||||||
return typ * len
|
return typ * len
|
||||||
|
|
||||||
################################################################
|
################################################################
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import ctypes
|
import ctypes
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import warnings
|
from ctypes import (Structure, Array, ARRAY, sizeof, addressof,
|
||||||
from ctypes import (Structure, Array, sizeof, addressof,
|
|
||||||
create_string_buffer, create_unicode_buffer,
|
create_string_buffer, create_unicode_buffer,
|
||||||
c_char, c_wchar, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
|
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)
|
c_long, c_ulonglong, c_float, c_double, c_longdouble)
|
||||||
|
@ -17,13 +16,6 @@ formats = c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, \
|
||||||
c_long, c_ulonglong, c_float, c_double, c_longdouble
|
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):
|
class ArrayTestCase(unittest.TestCase):
|
||||||
def test_inheritance_hierarchy(self):
|
def test_inheritance_hierarchy(self):
|
||||||
self.assertEqual(Array.mro(), [Array, _CData, object])
|
self.assertEqual(Array.mro(), [Array, _CData, object])
|
||||||
|
@ -275,10 +267,6 @@ class ArrayTestCase(unittest.TestCase):
|
||||||
def test_large_array(self, size):
|
def test_large_array(self, size):
|
||||||
c_char * size
|
c_char * size
|
||||||
|
|
||||||
def test_deprecation(self):
|
|
||||||
with self.assertWarns(DeprecationWarning):
|
|
||||||
CharArray = ctypes.ARRAY(c_char, 3)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -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…
Add table
Add a link
Reference in a new issue