From 4913e8a70d93d743412d51987505202dfb47d717 Mon Sep 17 00:00:00 2001 From: Vyron Vasileiadis Date: Mon, 27 Jul 2026 11:17:46 +0300 Subject: [PATCH] gh-154757: Remove the deprecated Py_UNICODE type Py_UNICODE was a typedef to wchar_t, deprecated by PEP 393 since Python 3.3 and at runtime since Python 3.13, and scheduled for removal in 3.16. Nothing in CPython used it: the Argument Clinic converter of the same name generates const wchar_t *, and the typedef is not part of the stable ABI. The documentation references to it are kept, with the link suppressed, as was done for PyWeakref_GetObject in GH-133657. --- Doc/c-api/unicode.rst | 16 +--------------- .../c-api-pending-removal-in-3.16.rst | 2 -- Doc/tools/removed-ids.txt | 1 + Doc/whatsnew/3.11.rst | 2 +- Doc/whatsnew/3.16.rst | 5 +++++ Doc/whatsnew/3.3.rst | 10 +++++----- Include/cpython/unicodeobject.h | 6 ++---- ...026-07-27-08-12-36.gh-issue-154757.XIuwa8.rst | 3 +++ 8 files changed, 18 insertions(+), 27 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2026-07-27-08-12-36.gh-issue-154757.XIuwa8.rst diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 9bf801ad608c77..9049fc41659b1d 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -17,7 +17,7 @@ points must be below 1114112 (which is the full Unicode range). UTF-8 representation is created on demand and cached in the Unicode object. .. note:: - The :c:type:`Py_UNICODE` representation has been removed since Python 3.12 + The :c:type:`!Py_UNICODE` representation has been removed since Python 3.12 with deprecated APIs. See :pep:`623` for more information. @@ -1943,20 +1943,6 @@ Deprecated API The following API is deprecated. -.. c:type:: Py_UNICODE - - This is a typedef of :c:type:`wchar_t`, which is a 16-bit type or 32-bit type - depending on the platform. - Please use :c:type:`wchar_t` directly instead. - - .. versionchanged:: 3.3 - In previous versions, this was a 16-bit type or a 32-bit type depending on - whether you selected a "narrow" or "wide" Unicode version of Python at - build time. - - .. deprecated-removed:: 3.13 3.16 - - .. c:function:: int PyUnicode_READY(PyObject *unicode) Do nothing and return ``0``. diff --git a/Doc/deprecations/c-api-pending-removal-in-3.16.rst b/Doc/deprecations/c-api-pending-removal-in-3.16.rst index fe2d91cf316b18..d39bd845fe09cc 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.16.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.16.rst @@ -83,5 +83,3 @@ Pending removal in Python 3.16 The :c:func:`Py_InitializeFromConfig` API should be used with :c:type:`PyConfig` to set these options. Or :c:func:`PyConfig_Get` can be used to get these options at runtime. - -* :c:type:`Py_UNICODE` which was deprecated by :pep:`393`. diff --git a/Doc/tools/removed-ids.txt b/Doc/tools/removed-ids.txt index 7796d15f4d2735..e31bc112293eed 100644 --- a/Doc/tools/removed-ids.txt +++ b/Doc/tools/removed-ids.txt @@ -20,6 +20,7 @@ deprecations/index.html: c-api-pending-removal-in-python-3-16 using/configure.html: cmdoption-with-system-libmpdec # Removed APIs +c-api/unicode.html: c.Py_UNICODE library/symtable.html: symtable.Class.get_methods library/sys.html: sys._enablelegacywindowsfsencoding c-api/import.html: c.PyImport_LazyImportsMode.PyImport_LAZY_NONE diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 4adb5cbd1b7d3b..665f0a0e94f5e4 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -2689,7 +2689,7 @@ Removed .. _whatsnew311-pep624: -* Remove the :c:type:`Py_UNICODE` encoder APIs, +* Remove the :c:type:`!Py_UNICODE` encoder APIs, as they have been deprecated since Python 3.3, are little used and are inefficient relative to the recommended alternatives. diff --git a/Doc/whatsnew/3.16.rst b/Doc/whatsnew/3.16.rst index 06e831ea1e3463..cd67aafb577bcd 100644 --- a/Doc/whatsnew/3.16.rst +++ b/Doc/whatsnew/3.16.rst @@ -841,3 +841,8 @@ Deprecated C APIs Removed C APIs -------------- + +* Remove the deprecated :c:type:`!Py_UNICODE` type, a typedef to + :c:type:`wchar_t` deprecated by :pep:`393` since Python 3.3 and at runtime + since Python 3.13. Use :c:type:`wchar_t` instead. + (Contributed by Vyron Vasileiadis in :gh:`154757`.) diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index 02fd264e53e1b0..37801d5a4fbed6 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -2265,11 +2265,11 @@ Deprecated Python modules, functions and methods Deprecated functions and types of the C API ------------------------------------------- -The :c:type:`Py_UNICODE` has been deprecated by :pep:`393` and will be +The :c:type:`!Py_UNICODE` has been deprecated by :pep:`393` and will be removed in Python 4. All functions using this type are deprecated: -Unicode functions and methods using :c:type:`Py_UNICODE` and -:c:expr:`Py_UNICODE*` types: +Unicode functions and methods using :c:type:`!Py_UNICODE` and +``Py_UNICODE*`` types: * :c:macro:`!PyUnicode_FromUnicode`: use :c:func:`PyUnicode_FromWideChar` or :c:func:`PyUnicode_FromKindAndData` @@ -2329,7 +2329,7 @@ Deprecated features ------------------- The :mod:`array` module's ``'u'`` format code is now deprecated and will be -removed in Python 4 together with the rest of the (:c:type:`Py_UNICODE`) API. +removed in Python 4 together with the rest of the (:c:type:`!Py_UNICODE`) API. Porting to Python 3.3 @@ -2470,7 +2470,7 @@ Porting C code All extensions relying on the relevant parts in ``memoryobject.h`` or ``object.h`` must be rebuilt. -* Due to :ref:`PEP 393 `, the :c:type:`Py_UNICODE` type and all +* Due to :ref:`PEP 393 `, the :c:type:`!Py_UNICODE` type and all functions using this type are deprecated (but will stay available for at least five years). If you were using low-level Unicode APIs to construct and access unicode objects and you want to benefit of the diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index ea91f4158eb392..5bcc59d103a59a 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -2,12 +2,10 @@ # error "this header file must not be included directly" #endif -/* Py_UNICODE was the native Unicode storage format (code unit) used by +/* PY_UNICODE_TYPE was the native Unicode storage format (code unit) used by Python and represents a single Unicode element in the Unicode type. - With PEP 393, Py_UNICODE is deprecated and replaced with a - typedef to wchar_t. */ + With PEP 393, it is deprecated and replaced with a typedef to wchar_t. */ Py_DEPRECATED(3.13) typedef wchar_t PY_UNICODE_TYPE; -Py_DEPRECATED(3.13) typedef wchar_t Py_UNICODE; /* --- Internal Unicode Operations ---------------------------------------- */ diff --git a/Misc/NEWS.d/next/C_API/2026-07-27-08-12-36.gh-issue-154757.XIuwa8.rst b/Misc/NEWS.d/next/C_API/2026-07-27-08-12-36.gh-issue-154757.XIuwa8.rst new file mode 100644 index 00000000000000..fc8723fc6d92b2 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-07-27-08-12-36.gh-issue-154757.XIuwa8.rst @@ -0,0 +1,3 @@ +Remove the deprecated :c:type:`!Py_UNICODE` type. It was a typedef to +:c:type:`wchar_t`, deprecated by :pep:`393` since Python 3.3 and at runtime +since Python 3.13. Use :c:type:`wchar_t` instead.