Skip to content

Commit f6fb498

Browse files
gh-132798: Schedule removal of PyUnicode_AsDecoded/Encoded functions for 3.15 (#132799)
Co-authored-by: Victor Stinner <[email protected]>
1 parent 8783cec commit f6fb498

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

Doc/deprecations/c-api-pending-removal-in-3.15.rst

+10
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Pending removal in Python 3.15
1010
:c:func:`PyWeakref_GetRef` on Python 3.12 and older.
1111
* :c:type:`Py_UNICODE` type and the :c:macro:`!Py_UNICODE_WIDE` macro:
1212
Use :c:type:`wchar_t` instead.
13+
* :c:func:`!PyUnicode_AsDecodedObject`:
14+
Use :c:func:`PyCodec_Decode` instead.
15+
* :c:func:`!PyUnicode_AsDecodedUnicode`:
16+
Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64")
17+
may return a type other than :class:`str`, such as :class:`bytes`.
18+
* :c:func:`!PyUnicode_AsEncodedObject`:
19+
Use :c:func:`PyCodec_Encode` instead.
20+
* :c:func:`!PyUnicode_AsEncodedUnicode`:
21+
Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64")
22+
may return a type other than :class:`bytes`, such as :class:`str`.
1323
* Python initialization functions, deprecated in Python 3.13:
1424

1525
* :c:func:`Py_GetPath`:

Doc/deprecations/c-api-pending-removal-in-future.rst

-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ although there is currently no date scheduled for their removal.
1818
Use :c:func:`PyOS_AfterFork_Child` instead.
1919
* :c:func:`PySlice_GetIndicesEx`:
2020
Use :c:func:`PySlice_Unpack` and :c:func:`PySlice_AdjustIndices` instead.
21-
* :c:func:`!PyUnicode_AsDecodedObject`:
22-
Use :c:func:`PyCodec_Decode` instead.
23-
* :c:func:`!PyUnicode_AsDecodedUnicode`:
24-
Use :c:func:`PyCodec_Decode` instead.
25-
* :c:func:`!PyUnicode_AsEncodedObject`:
26-
Use :c:func:`PyCodec_Encode` instead.
27-
* :c:func:`!PyUnicode_AsEncodedUnicode`:
28-
Use :c:func:`PyCodec_Encode` instead.
2921
* :c:func:`PyUnicode_READY`:
3022
Unneeded since Python 3.12
3123
* :c:func:`!PyErr_Display`:

Include/unicodeobject.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode(
344344
/* Decode a Unicode object unicode and return the result as Python
345345
object.
346346
347-
This API is DEPRECATED. The only supported standard encoding is rot13.
347+
This API is DEPRECATED and will be removed in 3.15.
348+
The only supported standard encoding is rot13.
348349
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
349350
that decode from str. */
350351

@@ -357,7 +358,8 @@ Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject(
357358
/* Decode a Unicode object unicode and return the result as Unicode
358359
object.
359360
360-
This API is DEPRECATED. The only supported standard encoding is rot13.
361+
This API is DEPRECATED and will be removed in 3.15.
362+
The only supported standard encoding is rot13.
361363
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
362364
that decode from str to str. */
363365

@@ -370,7 +372,8 @@ Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode(
370372
/* Encodes a Unicode object and returns the result as Python
371373
object.
372374
373-
This API is DEPRECATED. It is superseded by PyUnicode_AsEncodedString()
375+
This API is DEPRECATED and will be removed in 3.15.
376+
It is superseded by PyUnicode_AsEncodedString()
374377
since all standard encodings (except rot13) encode str to bytes.
375378
Use PyCodec_Encode() for encoding with rot13 and non-standard codecs
376379
that encode form str to non-bytes. */
@@ -393,7 +396,8 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
393396
/* Encodes a Unicode object and returns the result as Unicode
394397
object.
395398
396-
This API is DEPRECATED. The only supported standard encodings is rot13.
399+
This API is DEPRECATED and will be removed in 3.15.
400+
The only supported standard encodings is rot13.
397401
Use PyCodec_Encode() to encode with rot13 and non-standard codecs
398402
that encode from str to str. */
399403

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecated and undocumented functions :c:func:`!PyUnicode_AsEncodedObject`,
2+
:c:func:`!PyUnicode_AsDecodedObject`, :c:func:`!PyUnicode_AsEncodedUnicode`
3+
and :c:func:`!PyUnicode_AsDecodedUnicode` are scheduled for removal in 3.15.

Objects/unicodeobject.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -3733,7 +3733,8 @@ PyUnicode_AsDecodedObject(PyObject *unicode,
37333733
}
37343734

37353735
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3736-
"PyUnicode_AsDecodedObject() is deprecated; "
3736+
"PyUnicode_AsDecodedObject() is deprecated "
3737+
"and will be removed in 3.15; "
37373738
"use PyCodec_Decode() to decode from str", 1) < 0)
37383739
return NULL;
37393740

@@ -3757,7 +3758,8 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode,
37573758
}
37583759

37593760
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3760-
"PyUnicode_AsDecodedUnicode() is deprecated; "
3761+
"PyUnicode_AsDecodedUnicode() is deprecated "
3762+
"and will be removed in 3.15; "
37613763
"use PyCodec_Decode() to decode from str to str", 1) < 0)
37623764
return NULL;
37633765

@@ -3796,7 +3798,8 @@ PyUnicode_AsEncodedObject(PyObject *unicode,
37963798
}
37973799

37983800
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3799-
"PyUnicode_AsEncodedObject() is deprecated; "
3801+
"PyUnicode_AsEncodedObject() is deprecated "
3802+
"and will be removed in 3.15; "
38003803
"use PyUnicode_AsEncodedString() to encode from str to bytes "
38013804
"or PyCodec_Encode() for generic encoding", 1) < 0)
38023805
return NULL;
@@ -4019,7 +4022,8 @@ PyUnicode_AsEncodedUnicode(PyObject *unicode,
40194022
}
40204023

40214024
if (PyErr_WarnEx(PyExc_DeprecationWarning,
4022-
"PyUnicode_AsEncodedUnicode() is deprecated; "
4025+
"PyUnicode_AsEncodedUnicode() is deprecated "
4026+
"and will be removed in 3.15; "
40234027
"use PyCodec_Encode() to encode from str to str", 1) < 0)
40244028
return NULL;
40254029

0 commit comments

Comments
 (0)