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
(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
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)
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])
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()