Hi,
Python 3.14 introduced F and D formats in the struct module for complex numbers (32-bit and 64-bit). F and D were chosen for compatibility with numpy, but sadly there was a misunderstanding:
F and D are NumPy's "dtype" typecodes, which are user-facing API, and single-character. Defined by NumPy.
- Buffer protocol format strings (
Zf and Zd), which are under-the-hood serialization details. Defined by PEP 3118.
Numpy uses Zf and Zd buffer formats, defined by PEP 3118, for 15 years (since numpy 1.6). PEP 3118 defines the Zd format for 19 years (commit).
Python 3.15 beta1 was modified to accept Zf and Zd formats in array, ctypes, struct and memoryview for better compatibility with numpy. This change was endorsed by the Steering Council.
So Python 3.16 supports "Python" F / D formats and Numpy/PEP 3118 Zd / Zf buffer formats in the struct module.
I propose deprecating the F and D formats in the struct module (emit DeprecationWarning warning) in Python 3.16, and soft deprecate them in Python 3.15 documentation (but not in Python 3.14 which doesn't support Zf / Zd). The deprecation will follow PEP 387 policy: keep the deprecated feature for 5 years before removing it (I don't think that there is an urgency to remove F and D formats).
Note: Only the struct module accepts F / D formats: array, ctypes and memoryview use Zf / Zd formats in Python 3.15 instead.
Note 2: Before the 3.14 final release, ctypes and struct used C (double complex) and E (float complex) formats. These formats were replaced with D and F for compatibility with numpy in Python 3.14 final release.
Victor
Hi,
Python 3.14 introduced
FandDformats in thestructmodule for complex numbers (32-bit and 64-bit).FandDwere chosen for compatibility withnumpy, but sadly there was a misunderstanding:FandDare NumPy's "dtype" typecodes, which are user-facing API, and single-character. Defined by NumPy.ZfandZd), which are under-the-hood serialization details. Defined by PEP 3118.Numpy uses
ZfandZdbuffer formats, defined by PEP 3118, for 15 years (since numpy 1.6). PEP 3118 defines theZdformat for 19 years (commit).Python 3.15 beta1 was modified to accept
ZfandZdformats inarray,ctypes,structandmemoryviewfor better compatibility with numpy. This change was endorsed by the Steering Council.So Python 3.16 supports "Python"
F/Dformats and Numpy/PEP 3118Zd/Zfbuffer formats in thestructmodule.I propose deprecating the
FandDformats in thestructmodule (emitDeprecationWarningwarning) in Python 3.16, and soft deprecate them in Python 3.15 documentation (but not in Python 3.14 which doesn't supportZf/Zd). The deprecation will follow PEP 387 policy: keep the deprecated feature for 5 years before removing it (I don't think that there is an urgency to removeFandDformats).Note: Only the
structmodule acceptsF/Dformats:array,ctypesandmemoryviewuseZf/Zdformats in Python 3.15 instead.Note 2: Before the 3.14 final release,
ctypesandstructusedC(double complex) andE(float complex) formats. These formats were replaced withDandFfor compatibility with numpy in Python 3.14 final release.Victor