Skip to content

Commit 4fd1095

Browse files
gh-133610: Remove PyUnicode_AsDecoded/Encoded functions (#133612)
1 parent f34ec09 commit 4fd1095

File tree

6 files changed

+26
-90
lines changed

6 files changed

+26
-90
lines changed

Doc/data/stable_abi.dat

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/whatsnew/3.15.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,21 @@ Deprecated C APIs
167167
Removed C APIs
168168
--------------
169169

170+
* Remove deprecated ``PyUnicode`` functions:
171+
172+
* :c:func:`!PyUnicode_AsDecodedObject`:
173+
Use :c:func:`PyCodec_Decode` instead.
174+
* :c:func:`!PyUnicode_AsDecodedUnicode`:
175+
Use :c:func:`PyCodec_Decode` instead; Note that some codecs (for example, "base64")
176+
may return a type other than :class:`str`, such as :class:`bytes`.
177+
* :c:func:`!PyUnicode_AsEncodedObject`:
178+
Use :c:func:`PyCodec_Encode` instead.
179+
* :c:func:`!PyUnicode_AsEncodedUnicode`:
180+
Use :c:func:`PyCodec_Encode` instead; Note that some codecs (for example, "base64")
181+
may return a type other than :class:`bytes`, such as :class:`str`.
182+
183+
(Contributed by Stan Ulbrych in :gh:`133612`)
184+
170185
* :c:func:`!PyImport_ImportModuleNoBlock`: deprecated alias
171186
of :c:func:`PyImport_ImportModule`.
172187

Include/unicodeobject.h

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -341,49 +341,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode(
341341
const char *errors /* error handling */
342342
);
343343

344-
/* Decode a Unicode object unicode and return the result as Python
345-
object.
346-
347-
This API is DEPRECATED and will be removed in 3.15.
348-
The only supported standard encoding is rot13.
349-
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
350-
that decode from str. */
351-
352-
Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject(
353-
PyObject *unicode, /* Unicode object */
354-
const char *encoding, /* encoding */
355-
const char *errors /* error handling */
356-
);
357-
358-
/* Decode a Unicode object unicode and return the result as Unicode
359-
object.
360-
361-
This API is DEPRECATED and will be removed in 3.15.
362-
The only supported standard encoding is rot13.
363-
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
364-
that decode from str to str. */
365-
366-
Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode(
367-
PyObject *unicode, /* Unicode object */
368-
const char *encoding, /* encoding */
369-
const char *errors /* error handling */
370-
);
371-
372-
/* Encodes a Unicode object and returns the result as Python
373-
object.
374-
375-
This API is DEPRECATED and will be removed in 3.15.
376-
It is superseded by PyUnicode_AsEncodedString()
377-
since all standard encodings (except rot13) encode str to bytes.
378-
Use PyCodec_Encode() for encoding with rot13 and non-standard codecs
379-
that encode form str to non-bytes. */
380-
381-
Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject(
382-
PyObject *unicode, /* Unicode object */
383-
const char *encoding, /* encoding */
384-
const char *errors /* error handling */
385-
);
386-
387344
/* Encodes a Unicode object and returns the result as Python string
388345
object. */
389346

@@ -393,20 +350,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
393350
const char *errors /* error handling */
394351
);
395352

396-
/* Encodes a Unicode object and returns the result as Unicode
397-
object.
398-
399-
This API is DEPRECATED and will be removed in 3.15.
400-
The only supported standard encodings is rot13.
401-
Use PyCodec_Encode() to encode with rot13 and non-standard codecs
402-
that encode from str to str. */
403-
404-
Py_DEPRECATED(3.6) PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode(
405-
PyObject *unicode, /* Unicode object */
406-
const char *encoding, /* encoding */
407-
const char *errors /* error handling */
408-
);
409-
410353
/* Build an encoding map. */
411354

412355
PyAPI_FUNC(PyObject*) PyUnicode_BuildEncodingMap(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove deprecated functions :c:func:`!PyUnicode_AsDecodedObject`,
2+
:c:func:`!PyUnicode_AsDecodedUnicode`, :c:func:`!PyUnicode_AsEncodedObject`,
3+
and :c:func:`!PyUnicode_AsEncodedUnicode`.

Misc/stable_abi.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,14 +1463,18 @@
14631463
added = '3.2'
14641464
[function.PyUnicode_AsDecodedObject]
14651465
added = '3.2'
1466+
abi_only = true
14661467
[function.PyUnicode_AsDecodedUnicode]
14671468
added = '3.2'
1469+
abi_only = true
14681470
[function.PyUnicode_AsEncodedObject]
14691471
added = '3.2'
1472+
abi_only = true
14701473
[function.PyUnicode_AsEncodedString]
14711474
added = '3.2'
14721475
[function.PyUnicode_AsEncodedUnicode]
14731476
added = '3.2'
1477+
abi_only = true
14741478
[function.PyUnicode_AsLatin1String]
14751479
added = '3.2'
14761480
[function.PyUnicode_AsRawUnicodeEscapeString]

Objects/unicodeobject.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,7 +3730,7 @@ PyUnicode_Decode(const char *s,
37303730
return NULL;
37313731
}
37323732

3733-
PyObject *
3733+
PyAPI_FUNC(PyObject *)
37343734
PyUnicode_AsDecodedObject(PyObject *unicode,
37353735
const char *encoding,
37363736
const char *errors)
@@ -3740,20 +3740,14 @@ PyUnicode_AsDecodedObject(PyObject *unicode,
37403740
return NULL;
37413741
}
37423742

3743-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3744-
"PyUnicode_AsDecodedObject() is deprecated "
3745-
"and will be removed in 3.15; "
3746-
"use PyCodec_Decode() to decode from str", 1) < 0)
3747-
return NULL;
3748-
37493743
if (encoding == NULL)
37503744
encoding = PyUnicode_GetDefaultEncoding();
37513745

37523746
/* Decode via the codec registry */
37533747
return PyCodec_Decode(unicode, encoding, errors);
37543748
}
37553749

3756-
PyObject *
3750+
PyAPI_FUNC(PyObject *)
37573751
PyUnicode_AsDecodedUnicode(PyObject *unicode,
37583752
const char *encoding,
37593753
const char *errors)
@@ -3765,12 +3759,6 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode,
37653759
goto onError;
37663760
}
37673761

3768-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3769-
"PyUnicode_AsDecodedUnicode() is deprecated "
3770-
"and will be removed in 3.15; "
3771-
"use PyCodec_Decode() to decode from str to str", 1) < 0)
3772-
return NULL;
3773-
37743762
if (encoding == NULL)
37753763
encoding = PyUnicode_GetDefaultEncoding();
37763764

@@ -3793,7 +3781,7 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode,
37933781
return NULL;
37943782
}
37953783

3796-
PyObject *
3784+
PyAPI_FUNC(PyObject *)
37973785
PyUnicode_AsEncodedObject(PyObject *unicode,
37983786
const char *encoding,
37993787
const char *errors)
@@ -3805,13 +3793,6 @@ PyUnicode_AsEncodedObject(PyObject *unicode,
38053793
goto onError;
38063794
}
38073795

3808-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3809-
"PyUnicode_AsEncodedObject() is deprecated "
3810-
"and will be removed in 3.15; "
3811-
"use PyUnicode_AsEncodedString() to encode from str to bytes "
3812-
"or PyCodec_Encode() for generic encoding", 1) < 0)
3813-
return NULL;
3814-
38153796
if (encoding == NULL)
38163797
encoding = PyUnicode_GetDefaultEncoding();
38173798

@@ -4017,7 +3998,7 @@ PyUnicode_AsEncodedString(PyObject *unicode,
40173998
return NULL;
40183999
}
40194000

4020-
PyObject *
4001+
PyAPI_FUNC(PyObject *)
40214002
PyUnicode_AsEncodedUnicode(PyObject *unicode,
40224003
const char *encoding,
40234004
const char *errors)
@@ -4029,12 +4010,6 @@ PyUnicode_AsEncodedUnicode(PyObject *unicode,
40294010
goto onError;
40304011
}
40314012

4032-
if (PyErr_WarnEx(PyExc_DeprecationWarning,
4033-
"PyUnicode_AsEncodedUnicode() is deprecated "
4034-
"and will be removed in 3.15; "
4035-
"use PyCodec_Encode() to encode from str to str", 1) < 0)
4036-
return NULL;
4037-
40384013
if (encoding == NULL)
40394014
encoding = PyUnicode_GetDefaultEncoding();
40404015

0 commit comments

Comments
 (0)