https://github.com/python/cpython/commit/4fd10952800413ce615bba067cf5dfb7899a42c8
commit: 4fd10952800413ce615bba067cf5dfb7899a42c8
branch: main
author: Stan Ulbrych <89152624+stanfromirel...@users.noreply.github.com>
committer: vstinner <vstin...@python.org>
date: 2025-05-09T17:31:24+02:00
summary:

gh-133610: Remove PyUnicode_AsDecoded/Encoded functions (#133612)

files:
A Misc/NEWS.d/next/C_API/2025-05-07-21-18-00.gh-issue-133610.asdfjs.rst
M Doc/data/stable_abi.dat
M Doc/whatsnew/3.15.rst
M Include/unicodeobject.h
M Misc/stable_abi.toml
M Objects/unicodeobject.c

diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index d84addc7ecf851..e71a40e55e918c 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -739,11 +739,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,,
diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst
index f92e383cce570f..d1e58c1b764eb9 100644
--- a/Doc/whatsnew/3.15.rst
+++ b/Doc/whatsnew/3.15.rst
@@ -167,6 +167,21 @@ Deprecated C APIs
 Removed C APIs
 --------------
 
+* Remove deprecated ``PyUnicode`` functions:
+
+  * :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`.
 
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 76bfaab26ed1b6..d38919a8ea9b62 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -1463,14 +1463,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..f3f0c9646a652e 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();
 

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to