Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0093907

Browse filesBrowse files
Issue #28426: Deprecated undocumented functions PyUnicode_AsEncodedObject(),
PyUnicode_AsDecodedObject(), PyUnicode_AsDecodedUnicode() and PyUnicode_AsEncodedUnicode().
1 parent 802426f commit 0093907
Copy full SHA for 0093907

File tree

4 files changed

+57
-9
lines changed
Filter options

4 files changed

+57
-9
lines changed

‎Doc/whatsnew/3.6.rst

Copy file name to clipboardExpand all lines: Doc/whatsnew/3.6.rst
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,10 @@ Deprecated Python modules, functions and methods
12301230
Deprecated functions and types of the C API
12311231
-------------------------------------------
12321232

1233-
* None yet.
1233+
* Undocumented functions :c:func:`PyUnicode_AsEncodedObject`,
1234+
:c:func:`PyUnicode_AsDecodedObject`, :c:func:`PyUnicode_AsEncodedUnicode`
1235+
and :c:func:`PyUnicode_AsDecodedUnicode` are deprecated now.
1236+
Use :ref:`generic codec based API <codec-registry>` instead.
12341237

12351238

12361239
Deprecated features

‎Include/unicodeobject.h

Copy file name to clipboardExpand all lines: Include/unicodeobject.h
+25-8Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,22 +1171,30 @@ PyAPI_FUNC(PyObject*) PyUnicode_Decode(
11711171
);
11721172

11731173
/* Decode a Unicode object unicode and return the result as Python
1174-
object. */
1174+
object.
1175+
1176+
This API is DEPRECATED. The only supported standard encoding is rot13.
1177+
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
1178+
that decode from str. */
11751179

11761180
PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedObject(
11771181
PyObject *unicode, /* Unicode object */
11781182
const char *encoding, /* encoding */
11791183
const char *errors /* error handling */
1180-
);
1184+
) Py_DEPRECATED(3.6);
11811185

11821186
/* Decode a Unicode object unicode and return the result as Unicode
1183-
object. */
1187+
object.
1188+
1189+
This API is DEPRECATED. The only supported standard encoding is rot13.
1190+
Use PyCodec_Decode() to decode with rot13 and non-standard codecs
1191+
that decode from str to str. */
11841192

11851193
PyAPI_FUNC(PyObject*) PyUnicode_AsDecodedUnicode(
11861194
PyObject *unicode, /* Unicode object */
11871195
const char *encoding, /* encoding */
11881196
const char *errors /* error handling */
1189-
);
1197+
) Py_DEPRECATED(3.6);
11901198

11911199
/* Encodes a Py_UNICODE buffer of the given size and returns a
11921200
Python string object. */
@@ -1201,13 +1209,18 @@ PyAPI_FUNC(PyObject*) PyUnicode_Encode(
12011209
#endif
12021210

12031211
/* Encodes a Unicode object and returns the result as Python
1204-
object. */
1212+
object.
1213+
1214+
This API is DEPRECATED. It is superceeded by PyUnicode_AsEncodedString()
1215+
since all standard encodings (except rot13) encode str to bytes.
1216+
Use PyCodec_Encode() for encoding with rot13 and non-standard codecs
1217+
that encode form str to non-bytes. */
12051218

12061219
PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedObject(
12071220
PyObject *unicode, /* Unicode object */
12081221
const char *encoding, /* encoding */
12091222
const char *errors /* error handling */
1210-
);
1223+
) Py_DEPRECATED(3.6);
12111224

12121225
/* Encodes a Unicode object and returns the result as Python string
12131226
object. */
@@ -1219,13 +1232,17 @@ PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedString(
12191232
);
12201233

12211234
/* Encodes a Unicode object and returns the result as Unicode
1222-
object. */
1235+
object.
1236+
1237+
This API is DEPRECATED. The only supported standard encodings is rot13.
1238+
Use PyCodec_Encode() to encode with rot13 and non-standard codecs
1239+
that encode from str to str. */
12231240

12241241
PyAPI_FUNC(PyObject*) PyUnicode_AsEncodedUnicode(
12251242
PyObject *unicode, /* Unicode object */
12261243
const char *encoding, /* encoding */
12271244
const char *errors /* error handling */
1228-
);
1245+
) Py_DEPRECATED(3.6);
12291246

12301247
/* Build an encoding map. */
12311248

‎Misc/NEWS

Copy file name to clipboardExpand all lines: Misc/NEWS
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ Windows
349349

350350
- Issue #28138: Windows ._pth file should allow import site
351351

352+
C API
353+
-----
354+
355+
- Issue #28426: Deprecated undocumented functions PyUnicode_AsEncodedObject(),
356+
PyUnicode_AsDecodedObject(), PyUnicode_AsDecodedUnicode() and
357+
PyUnicode_AsEncodedUnicode().
358+
352359
Build
353360
-----
354361

‎Objects/unicodeobject.c

Copy file name to clipboardExpand all lines: Objects/unicodeobject.c
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,11 @@ PyUnicode_AsDecodedObject(PyObject *unicode,
32413241
return NULL;
32423242
}
32433243

3244+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3245+
"PyUnicode_AsDecodedObject() is deprecated; "
3246+
"use PyCodec_Decode() to decode from str", 1) < 0)
3247+
return NULL;
3248+
32443249
if (encoding == NULL)
32453250
encoding = PyUnicode_GetDefaultEncoding();
32463251

@@ -3260,6 +3265,11 @@ PyUnicode_AsDecodedUnicode(PyObject *unicode,
32603265
goto onError;
32613266
}
32623267

3268+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3269+
"PyUnicode_AsDecodedUnicode() is deprecated; "
3270+
"use PyCodec_Decode() to decode from str to str", 1) < 0)
3271+
return NULL;
3272+
32633273
if (encoding == NULL)
32643274
encoding = PyUnicode_GetDefaultEncoding();
32653275

@@ -3310,6 +3320,12 @@ PyUnicode_AsEncodedObject(PyObject *unicode,
33103320
goto onError;
33113321
}
33123322

3323+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3324+
"PyUnicode_AsEncodedObject() is deprecated; "
3325+
"use PyUnicode_AsEncodedString() to encode from str to bytes "
3326+
"or PyCodec_Encode() for generic encoding", 1) < 0)
3327+
return NULL;
3328+
33133329
if (encoding == NULL)
33143330
encoding = PyUnicode_GetDefaultEncoding();
33153331

@@ -3635,6 +3651,11 @@ PyUnicode_AsEncodedUnicode(PyObject *unicode,
36353651
goto onError;
36363652
}
36373653

3654+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
3655+
"PyUnicode_AsEncodedUnicode() is deprecated; "
3656+
"use PyCodec_Encode() to encode from str to str", 1) < 0)
3657+
return NULL;
3658+
36383659
if (encoding == NULL)
36393660
encoding = PyUnicode_GetDefaultEncoding();
36403661

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.