diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 586a1306d83c4c..6fff4c62a8b529 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -879,6 +879,15 @@ contextlib (Contributed by Alex Grönholm & Gregory P. Smith in :gh:`125862`.) +ctypes +------ + +* Change the ``format`` field of exported buffers from ``F``, ``D`` and ``G`` + to ``Zf``, ``Zd`` and ``Zg``, respectively, for compatibility with + the :pep:`3118` and NumPy. + (Contributed by Sergey B Kirpichev in :gh:`149344`.) + + dataclasses ----------- diff --git a/Lib/test/test_ctypes/test_pep3118.py b/Lib/test/test_ctypes/test_pep3118.py index 11a0744f5a8e36..9740e0c77b5c87 100644 --- a/Lib/test/test_ctypes/test_pep3118.py +++ b/Lib/test/test_ctypes/test_pep3118.py @@ -1,3 +1,4 @@ +import ctypes import re import sys import unittest @@ -231,6 +232,14 @@ class Complete(Structure): ] +if hasattr(ctypes, 'c_float_complex'): + c_float_complex = ctypes.c_float_complex + c_double_complex = ctypes.c_double_complex + c_longdouble_complex = ctypes.c_longdouble_complex + native_types.extend([(c_float_complex * 4, "' : '<'; + result[1] = 'Z'; + switch (code) { + case 'F': + result[2] = 'f'; + break; + case 'D': + result[2] = 'd'; + break; + default: + result[2] = 'g'; + } + result[3] = '\0'; + return result; + } +#endif default: /* The standard-size code is the same as the ctypes one */ pep_code = code;