From ba299e0d03aa4e8ad611c24c5123e9a9625058fa Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 7 May 2025 21:19:47 +0100 Subject: [PATCH 1/7] Remove --- .../c-api-pending-removal-in-3.15.rst | 10 ---- Doc/whatsnew/3.15.rst | 11 ++++ Include/unicodeobject.h | 57 ------------------- ...-05-07-21-18-00.gh-issue-133610.asdfjs.rst | 3 + Misc/stable_abi.toml | 4 ++ Objects/unicodeobject.c | 45 ++++++--------- 6 files changed, 34 insertions(+), 96 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2025-05-07-21-18-00.gh-issue-133610.asdfjs.rst diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst index a5cc8f1d5b3475..666a1622dd0b29 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -10,16 +10,6 @@ Pending removal in Python 3.15 :c:func:`PyWeakref_GetRef` on Python 3.12 and older. * :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro: Use :c:type:`wchar_t` instead. -* :c:func:`!PyUnicode_AsDecodedObject`: - Use :c:func:`PyCodec_Decode` instead. -* :c:func:`!PyUnicode_AsDecodedUnicode`: - Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64") - may return a type other than :class:`str`, such as :class:`bytes`. -* :c:func:`!PyUnicode_AsEncodedObject`: - Use :c:func:`PyCodec_Encode` instead. -* :c:func:`!PyUnicode_AsEncodedUnicode`: - Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") - may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: * :c:func:`Py_GetPath`: diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 41b2685d5d30fe..103073d78d4dc4 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -154,3 +154,14 @@ Deprecated C APIs Removed C APIs -------------- +* :c:func:`!PyUnicode_AsDecodedObject`: + Use :c:func:`PyCodec_Decode` instead. +* :c:func:`!PyUnicode_AsDecodedUnicode`: + Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`str`, such as :class:`bytes`. +* :c:func:`!PyUnicode_AsEncodedObject`: + Use :c:func:`PyCodec_Encode` instead. +* :c:func:`!PyUnicode_AsEncodedUnicode`: + Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`bytes`, such as :class:`str`. + diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index f8bcaecb98fb9c..b72d581ec25804 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -341,49 +341,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode( const char *errors /* error handling */ ); -/* Decode a Unicode object unicode and return the result as Python - object. - - This API is DEPRECATED and will be removed in 3.15. - The only supported standard encoding is rot13. - Use PyCodec_Decode() to decode with rot13 and non-standard codecs - that decode from str. */ - -Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject( - PyObject *unicode, /* Unicode object */ - const char *encoding, /* encoding */ - const char *errors /* error handling */ - ); - -/* Decode a Unicode object unicode and return the result as Unicode - object. - - This API is DEPRECATED and will be removed in 3.15. - The only supported standard encoding is rot13. - Use PyCodec_Decode() to decode with rot13 and non-standard codecs - that decode from str to str. */ - -Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode( - PyObject *unicode, /* Unicode object */ - const char *encoding, /* encoding */ - const char *errors /* error handling */ - ); - -/* Encodes a Unicode object and returns the result as Python - object. - - This API is DEPRECATED and will be removed in 3.15. - It is superseded by PyUnicode_AsEncodedString() - since all standard encodings (except rot13) encode str to bytes. - Use PyCodec_Encode() for encoding with rot13 and non-standard codecs - that encode form str to non-bytes. */ - -Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject( - PyObject *unicode, /* Unicode object */ - const char *encoding, /* encoding */ - const char *errors /* error handling */ - ); - /* Encodes a Unicode object and returns the result as Python string object. */ @@ -393,20 +350,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString( const char *errors /* error handling */ ); -/* Encodes a Unicode object and returns the result as Unicode - object. - - This API is DEPRECATED and will be removed in 3.15. - The only supported standard encodings is rot13. - Use PyCodec_Encode() to encode with rot13 and non-standard codecs - that encode from str to str. */ - -Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode( - PyObject *unicode, /* Unicode object */ - const char *encoding, /* encoding */ - const char *errors /* error handling */ - ); - /* Build an encoding map. */ PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap( diff --git a/Misc/NEWS.d/next/C_API/2025-05-07-21-18-00.gh-issue-133610.asdfjs.rst b/Misc/NEWS.d/next/C_API/2025-05-07-21-18-00.gh-issue-133610.asdfjs.rst new file mode 100644 index 00000000000000..bdc53331f6aa62 --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2025-05-07-21-18-00.gh-issue-133610.asdfjs.rst @@ -0,0 +1,3 @@ +Remove deprecated functions :c:func:`!PyUnicode_AsDecodedObject`, +:c:func:`!PyUnicode_AsDecodedUnicode`, :c:func:`!PyUnicode_AsEncodedObject`, +and :c:func:`!PyUnicode_AsEncodedUnicode`. diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml index d3e1f0db057023..4a09e2be7548e6 100644 --- a/Misc/stable_abi.toml +++ b/Misc/stable_abi.toml @@ -1462,14 +1462,18 @@ added = '3.2' [function.PyUnicode_AsDecodedObject] added = '3.2' + abi_only = true [function.PyUnicode_AsDecodedUnicode] added = '3.2' + abi_only = true [function.PyUnicode_AsEncodedObject] added = '3.2' + abi_only = true [function.PyUnicode_AsEncodedString] added = '3.2' [function.PyUnicode_AsEncodedUnicode] added = '3.2' + abi_only = true [function.PyUnicode_AsLatin1String] added = '3.2' [function.PyUnicode_AsRawUnicodeEscapeString] diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index eb3e1c48fd4050..3d86fa8af50902 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3730,7 +3730,7 @@ PyUnicode_Decode(const char *s, return NULL; } -PyObject * +PyAPI_FUNC(PyObject *) PyUnicode_AsDecodedObject(PyObject *unicode, const char *encoding, const char *errors) @@ -3740,12 +3740,6 @@ PyUnicode_AsDecodedObject(PyObject *unicode, return NULL; } - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PyUnicode_AsDecodedObject() is deprecated " - "and will be removed in 3.15; " - "use PyCodec_Decode() to decode from str", 1) < 0) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -3753,7 +3747,7 @@ PyUnicode_AsDecodedObject(PyObject *unicode, return PyCodec_Decode(unicode, encoding, errors); } -PyObject * +PyAPI_FUNC(PyObject *) PyUnicode_AsDecodedUnicode(PyObject *unicode, const char *encoding, const char *errors) @@ -3765,12 +3759,6 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode, goto onError; } - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PyUnicode_AsDecodedUnicode() is deprecated " - "and will be removed in 3.15; " - "use PyCodec_Decode() to decode from str to str", 1) < 0) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -3793,7 +3781,7 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode, return NULL; } -PyObject * +PyAPI_FUNC(PyObject *) PyUnicode_AsEncodedObject(PyObject *unicode, const char *encoding, const char *errors) @@ -3805,13 +3793,6 @@ PyUnicode_AsEncodedObject(PyObject *unicode, goto onError; } - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PyUnicode_AsEncodedObject() is deprecated " - "and will be removed in 3.15; " - "use PyUnicode_AsEncodedString() to encode from str to bytes " - "or PyCodec_Encode() for generic encoding", 1) < 0) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -4017,7 +3998,7 @@ PyUnicode_AsEncodedString(PyObject *unicode, return NULL; } -PyObject * +PyAPI_FUNC(PyObject *) PyUnicode_AsEncodedUnicode(PyObject *unicode, const char *encoding, const char *errors) @@ -4029,12 +4010,6 @@ PyUnicode_AsEncodedUnicode(PyObject *unicode, goto onError; } - if (PyErr_WarnEx(PyExc_DeprecationWarning, - "PyUnicode_AsEncodedUnicode() is deprecated " - "and will be removed in 3.15; " - "use PyCodec_Encode() to encode from str to str", 1) < 0) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -4308,6 +4283,18 @@ because it returned length of Py_UNICODE. But this function is part of stable abi, because it doesn't include Py_UNICODE in signature and it was not excluded from stable ABI in PEP 384. + + + + + + + + + + + + */ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(PyObject *unicode) From 602b834053c84fc30c6fea5f00984e285eccf60e Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 7 May 2025 21:20:59 +0100 Subject: [PATCH 2/7] Fixup --- Objects/unicodeobject.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3d86fa8af50902..f3f0c9646a652e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4283,18 +4283,6 @@ because it returned length of Py_UNICODE. But this function is part of stable abi, because it doesn't include Py_UNICODE in signature and it was not excluded from stable ABI in PEP 384. - - - - - - - - - - - - */ PyAPI_FUNC(Py_ssize_t) PyUnicode_GetSize(PyObject *unicode) From a6ac1e92a3c0904aedb0ee92a0248b24409a752f Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Wed, 7 May 2025 23:10:04 +0100 Subject: [PATCH 3/7] Fixup --- Doc/data/stable_abi.dat | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat index 3d68487d07baf2..1fb57955d031c5 100644 --- a/Doc/data/stable_abi.dat +++ b/Doc/data/stable_abi.dat @@ -740,11 +740,7 @@ func,PyUnicode_Append,3.2,, func,PyUnicode_AppendAndDel,3.2,, func,PyUnicode_AsASCIIString,3.2,, func,PyUnicode_AsCharmapString,3.2,, -func,PyUnicode_AsDecodedObject,3.2,, -func,PyUnicode_AsDecodedUnicode,3.2,, -func,PyUnicode_AsEncodedObject,3.2,, func,PyUnicode_AsEncodedString,3.2,, -func,PyUnicode_AsEncodedUnicode,3.2,, func,PyUnicode_AsLatin1String,3.2,, func,PyUnicode_AsMBCSString,3.7,on Windows, func,PyUnicode_AsRawUnicodeEscapeString,3.2,, From ea33f912c0cdc50b2b725bf198addd8c5463f362 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 8 May 2025 16:02:20 +0100 Subject: [PATCH 4/7] Victors Review --- .editorconfig | 2 +- Doc/whatsnew/3.15.rst | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.editorconfig b/.editorconfig index 5b04b32a89e3d2..a2ba1b7e7e255e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ indent_style = space indent_size = 4 [*.rst] -indent_size = 3 +indent_size = 2 [*.{js,yml,yaml}] indent_size = 2 diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 012b1746476b5a..b42468e3ad3c9e 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -164,15 +164,18 @@ Deprecated C APIs Removed C APIs -------------- -* :c:func:`!PyUnicode_AsDecodedObject`: - Use :c:func:`PyCodec_Decode` instead. -* :c:func:`!PyUnicode_AsDecodedUnicode`: - Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64") - may return a type other than :class:`str`, such as :class:`bytes`. -* :c:func:`!PyUnicode_AsEncodedObject`: - Use :c:func:`PyCodec_Encode` instead. -* :c:func:`!PyUnicode_AsEncodedUnicode`: - Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") - may return a type other than :class:`bytes`, such as :class:`str`. +* + * :c:func:`!PyUnicode_AsDecodedObject`: + Use :c:func:`PyCodec_Decode` instead. + * :c:func:`!PyUnicode_AsDecodedUnicode`: + Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`str`, such as :class:`bytes`. + * :c:func:`!PyUnicode_AsEncodedObject`: + Use :c:func:`PyCodec_Encode` instead. + * :c:func:`!PyUnicode_AsEncodedUnicode`: + Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`bytes`, such as :class:`str`. + (Contributed by Stan Ulbrych in :gh:`133612`) + * :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias of :c:func:`PyImport_ImportModule`. From 4d948c0897c977a874cc8cf0791ffda0c3dbef81 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 8 May 2025 16:42:07 +0100 Subject: [PATCH 5/7] Docs fixup --- Doc/whatsnew/3.15.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index b42468e3ad3c9e..952592dfbb2ec0 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -165,6 +165,7 @@ Removed C APIs -------------- * + * :c:func:`!PyUnicode_AsDecodedObject`: Use :c:func:`PyCodec_Decode` instead. * :c:func:`!PyUnicode_AsDecodedUnicode`: @@ -175,6 +176,7 @@ Removed C APIs * :c:func:`!PyUnicode_AsEncodedUnicode`: Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") may return a type other than :class:`bytes`, such as :class:`str`. + (Contributed by Stan Ulbrych in :gh:`133612`) * :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias From bb36c54f55ea04fdfbfcaf8c0652e0bb599c6d1d Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 8 May 2025 16:59:43 +0100 Subject: [PATCH 6/7] Cleanup --- .editorconfig | 2 +- Doc/whatsnew/3.15.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index a2ba1b7e7e255e..5b04b32a89e3d2 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,7 +9,7 @@ indent_style = space indent_size = 4 [*.rst] -indent_size = 2 +indent_size = 3 [*.{js,yml,yaml}] indent_size = 2 diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 952592dfbb2ec0..036ee207235310 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -164,7 +164,7 @@ Deprecated C APIs Removed C APIs -------------- -* +* Remove deprecated ``PyUnicode`` functions: * :c:func:`!PyUnicode_AsDecodedObject`: Use :c:func:`PyCodec_Decode` instead. From f2f51ccb0a2fef43b00ca149fd109160b0922659 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Thu, 8 May 2025 17:37:19 +0100 Subject: [PATCH 7/7] revert removal --- Doc/deprecations/c-api-pending-removal-in-3.15.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Doc/deprecations/c-api-pending-removal-in-3.15.rst b/Doc/deprecations/c-api-pending-removal-in-3.15.rst index 568d013e1825ff..a391566c82c2f1 100644 --- a/Doc/deprecations/c-api-pending-removal-in-3.15.rst +++ b/Doc/deprecations/c-api-pending-removal-in-3.15.rst @@ -10,6 +10,16 @@ Pending removal in Python 3.15 :c:func:`PyWeakref_GetRef` on Python 3.12 and older. * :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro: Use :c:type:`wchar_t` instead. +* :c:func:`!PyUnicode_AsDecodedObject`: + Use :c:func:`PyCodec_Decode` instead. +* :c:func:`!PyUnicode_AsDecodedUnicode`: + Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`str`, such as :class:`bytes`. +* :c:func:`!PyUnicode_AsEncodedObject`: + Use :c:func:`PyCodec_Encode` instead. +* :c:func:`!PyUnicode_AsEncodedUnicode`: + Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64") + may return a type other than :class:`bytes`, such as :class:`str`. * Python initialization functions, deprecated in Python 3.13: * :c:func:`Py_GetPath`: