Skip to content

Commit 583ee5a

Browse files
authored
bpo-41692: Deprecate PyUnicode_InternImmortal() (GH-22486)
The PyUnicode_InternImmortal() function is now deprecated and will be removed in Python 3.12: use PyUnicode_InternInPlace() instead.
1 parent 497126f commit 583ee5a

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ Porting to Python 3.10
299299
Unicode object without initial data.
300300
(Contributed by Inada Naoki in :issue:`36346`.)
301301

302+
Deprecated
303+
----------
304+
305+
* The ``PyUnicode_InternImmortal()`` function is now deprecated
306+
and will be removed in Python 3.12: use :c:func:`PyUnicode_InternInPlace`
307+
instead.
308+
(Contributed by Victor Stinner in :issue:`41692`.)
309+
302310
Removed
303311
-------
304312

Include/unicodeobject.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,14 @@ PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(
261261
);
262262

263263
PyAPI_FUNC(void) PyUnicode_InternInPlace(PyObject **);
264-
PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
265264
PyAPI_FUNC(PyObject *) PyUnicode_InternFromString(
266265
const char *u /* UTF-8 encoded string */
267266
);
268267

268+
// PyUnicode_InternImmortal() is deprecated since Python 3.10
269+
// and will be removed in Python 3.12. Use PyUnicode_InternInPlace() instead.
270+
Py_DEPRECATED(3.10) PyAPI_FUNC(void) PyUnicode_InternImmortal(PyObject **);
271+
269272
/* Use only if you know it's a string */
270273
#define PyUnicode_CHECK_INTERNED(op) \
271274
(((PyASCIIObject *)(op))->state.interned)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The ``PyUnicode_InternImmortal()`` function is now deprecated and will be
2+
removed in Python 3.12: use :c:func:`PyUnicode_InternInPlace` instead.
3+
Patch by Victor Stinner.

Objects/unicodeobject.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15764,6 +15764,15 @@ PyUnicode_InternInPlace(PyObject **p)
1576415764
void
1576515765
PyUnicode_InternImmortal(PyObject **p)
1576615766
{
15767+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
15768+
"PyUnicode_InternImmortal() is deprecated; "
15769+
"use PyUnicode_InternInPlace() instead", 1) < 0)
15770+
{
15771+
// The function has no return value, the exception cannot
15772+
// be reported to the caller, so just log it.
15773+
PyErr_WriteUnraisable(NULL);
15774+
}
15775+
1576715776
PyUnicode_InternInPlace(p);
1576815777
if (PyUnicode_CHECK_INTERNED(*p) != SSTATE_INTERNED_IMMORTAL) {
1576915778
_PyUnicode_STATE(*p).interned = SSTATE_INTERNED_IMMORTAL;

0 commit comments

Comments
 (0)