From ec9cf6b33a9b8a54df8a084655c1e4507aada93d Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 4 May 2026 05:22:52 +0300 Subject: [PATCH 1/5] gh-121249: deprecate support for complex types in the struct module --- Doc/deprecations/pending-removal-in-3.17.rst | 9 +++++++++ Doc/library/struct.rst | 3 +++ Doc/whatsnew/3.15.rst | 6 ++++++ .../2026-05-04-05-22-48.gh-issue-121249.XN06Fd.rst | 2 ++ 4 files changed, 20 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-05-04-05-22-48.gh-issue-121249.XN06Fd.rst diff --git a/Doc/deprecations/pending-removal-in-3.17.rst b/Doc/deprecations/pending-removal-in-3.17.rst index 952ffad64356d9..b2c66740e984a8 100644 --- a/Doc/deprecations/pending-removal-in-3.17.rst +++ b/Doc/deprecations/pending-removal-in-3.17.rst @@ -37,6 +37,15 @@ Pending removal in Python 3.17 is deprecated and scheduled for removal in Python 3.17. (Contributed by Stan Ulbrych in :gh:`136702`.) + +* :mod:`struct`: + + - Support the :c:expr:`float complex` and :c:expr:`double complex` C types in + the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` + respectively). + (Contributed by Sergey B Kirpichev in :gh:`121249`.) + + * :mod:`typing`: - Before Python 3.14, old-style unions were implemented using the private class diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index f504f931f0fa20..3b018e5139f40b 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -280,6 +280,9 @@ platform-dependent. .. versionchanged:: 3.14 Added support for the ``'F'`` and ``'D'`` formats. +.. deprecated-removed:: 3.15 3.17 + Support for the ``'F'`` and ``'D'`` formats. + .. seealso:: The :mod:`array` and :ref:`ctypes ` modules, diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 586a1306d83c4c..13d1b3231ef34f 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1950,6 +1950,12 @@ New deprecations (Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.) + - Support the :c:expr:`float complex` and :c:expr:`double complex` C types in + the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` + respectively). + (Contributed by Sergey B Kirpichev in :gh:`121249`.) + + * :mod:`typing`: * The following statements now cause ``DeprecationWarning``\ s to be emitted diff --git a/Misc/NEWS.d/next/Library/2026-05-04-05-22-48.gh-issue-121249.XN06Fd.rst b/Misc/NEWS.d/next/Library/2026-05-04-05-22-48.gh-issue-121249.XN06Fd.rst new file mode 100644 index 00000000000000..bf370f08d420c6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-05-04-05-22-48.gh-issue-121249.XN06Fd.rst @@ -0,0 +1,2 @@ +Deprecate support for complex types in the :mod:`struct` module (formatting +characters ``'F'`` and ``'D'`` respectively). From ae6c3c0583c69a2f0a02f94f3e6aa9d49245e196 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 05:32:20 +0300 Subject: [PATCH 2/5] adjust news --- Doc/whatsnew/3.15.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index c4603f09a6633b..c42491d6d74d8b 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -2054,9 +2054,8 @@ New deprecations (Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.) - - Support the :c:expr:`float complex` and :c:expr:`double complex` C types in - the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` - respectively). + - Support for ``'F'`` and ``'D'`` format type codes (the :c:expr:`float + complex` and :c:expr:`double complex` C types, respectively) (Contributed by Sergey B Kirpichev in :gh:`121249`.) From 8312af81cc2fd8aa9ce16af1766b851e94444efb Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 05:36:38 +0300 Subject: [PATCH 3/5] remove F/D from table --- Doc/library/struct.rst | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst index 621fac0fb84e7d..ed591cf300518f 100644 --- a/Doc/library/struct.rst +++ b/Doc/library/struct.rst @@ -260,10 +260,6 @@ platform-dependent. +--------+--------------------------+--------------------+----------------+------------+ | ``d`` | :c:expr:`double` | float | 8 | \(4) | +--------+--------------------------+--------------------+----------------+------------+ -| ``F`` | :c:expr:`float complex` | complex | 8 | \(10) | -+--------+--------------------------+--------------------+----------------+------------+ -| ``D`` | :c:expr:`double complex` | complex | 16 | \(10) | -+--------+--------------------------+--------------------+----------------+------------+ | ``Zf`` | :c:expr:`float complex` | complex | 8 | \(10) | +--------+--------------------------+--------------------+----------------+------------+ | ``Zd`` | :c:expr:`double complex` | complex | 16 | \(10) | @@ -379,13 +375,15 @@ Notes: are accepted. (10) - For the ``'F'`` and ``'D'`` format characters, the packed representation uses + For the ``'Zf'`` and ``'Zd'`` format characters, the packed representation uses the IEEE 754 binary32 and binary64 format for components of the complex number, regardless of the floating-point format used by the platform. - Note that complex types (``F``/``Zf`` and ``D``/``Zd``) are available unconditionally, + Note that complex types are available unconditionally, despite complex types being an optional feature in C. As specified in the C11 standard, each complex type is represented by a two-element C array containing, respectively, the real and imaginary parts. + The ``'F'`` and ``'D'`` (for ``'Zf'`` and ``'Zd'``, respectively) format + characters are supported for compatibility. A format character may be preceded by an integral repeat count. For example, From 0e600a59d11605ff60ca3eb8cad2e52244595d89 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 05:39:58 +0300 Subject: [PATCH 4/5] delay deprecation, as recommended in PEP 387 --- Doc/deprecations/pending-removal-in-3.17.rst | 8 -------- Doc/deprecations/pending-removal-in-3.20.rst | 9 ++++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.17.rst b/Doc/deprecations/pending-removal-in-3.17.rst index b2c66740e984a8..f4e9ede50457f2 100644 --- a/Doc/deprecations/pending-removal-in-3.17.rst +++ b/Doc/deprecations/pending-removal-in-3.17.rst @@ -38,14 +38,6 @@ Pending removal in Python 3.17 (Contributed by Stan Ulbrych in :gh:`136702`.) -* :mod:`struct`: - - - Support the :c:expr:`float complex` and :c:expr:`double complex` C types in - the :mod:`struct` module (formatting characters ``'F'`` and ``'D'`` - respectively). - (Contributed by Sergey B Kirpichev in :gh:`121249`.) - - * :mod:`typing`: - Before Python 3.14, old-style unions were implemented using the private class diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index 011565dfbb090d..d1c440a045dfea 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -1,13 +1,20 @@ Pending removal in Python 3.20 ------------------------------ -* Calling the ``__new__()`` method of :class:`struct.Struct` without the +* :mod:`struct`: + + - Calling the ``__new__()`` method of :class:`struct.Struct` without the *format* argument is deprecated and will be removed in Python 3.20. Calling :meth:`~object.__init__` method on initialized :class:`~struct.Struct` objects is deprecated and will be removed in Python 3.20. (Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.) + - Support for ``'F'`` and ``'D'`` format type codes (the :c:expr:`float + complex` and :c:expr:`double complex` C types, respectively) + (Contributed by Sergey B Kirpichev in :gh:`121249`.) + + * The ``__version__``, ``version`` and ``VERSION`` attributes have been deprecated in these standard library modules and will be removed in Python 3.20. Use :py:data:`sys.version_info` instead. From 344d2be1400885ad275c1ca0ac41b230563be8ea Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 5 May 2026 05:48:01 +0300 Subject: [PATCH 5/5] fix format --- Doc/deprecations/pending-removal-in-3.20.rst | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Doc/deprecations/pending-removal-in-3.20.rst b/Doc/deprecations/pending-removal-in-3.20.rst index d1c440a045dfea..7fa7168693b750 100644 --- a/Doc/deprecations/pending-removal-in-3.20.rst +++ b/Doc/deprecations/pending-removal-in-3.20.rst @@ -4,11 +4,10 @@ Pending removal in Python 3.20 * :mod:`struct`: - Calling the ``__new__()`` method of :class:`struct.Struct` without the - *format* argument is deprecated and will be removed in Python 3.20. Calling - :meth:`~object.__init__` method on initialized :class:`~struct.Struct` - objects is deprecated and will be removed in Python 3.20. - - (Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.) + *format* argument is deprecated and will be removed in Python 3.20. Calling + :meth:`~object.__init__` method on initialized :class:`~struct.Struct` + objects is deprecated and will be removed in Python 3.20. + (Contributed by Sergey B Kirpichev and Serhiy Storchaka in :gh:`143715`.) - Support for ``'F'`` and ``'D'`` format type codes (the :c:expr:`float complex` and :c:expr:`double complex` C types, respectively)