Deprecate immortal interned strings: PyUnicode_InternImmortal() #85858
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
assignee = None closed_at = <Date 2020-10-02.12:49:46.896> created_at = <Date 2020-09-02.13:59:25.913> labels = ['interpreter-core', '3.10'] title = 'Deprecate immortal interned strings: PyUnicode_InternImmortal()' updated_at = <Date 2021-12-08.11:28:35.305> user = 'https://github.com/vstinner'
activity = <Date 2021-12-08.11:28:35.305> actor = 'vstinner' assignee = 'none' closed = True closed_date = <Date 2020-10-02.12:49:46.896> closer = 'vstinner' components = ['Interpreter Core'] creation = <Date 2020-09-02.13:59:25.913> creator = 'vstinner' dependencies =  files =  hgrepos =  issue_num = 41692 keywords = ['patch'] message_count = 9.0 messages = ['376237', '376271', '376302', '376428', '377784', '377808', '377809', '393350', '408011'] nosy_count = 5.0 nosy_names = ['vstinner', 'methane', 'serhiy.storchaka', 'corona10', 'shihai1991'] pr_nums = ['22486'] priority = 'normal' resolution = 'fixed' stage = 'resolved' status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue41692' versions = ['Python 3.10']
The text was updated successfully, but these errors were encountered:
Python has the concept of "immortal" interned strings: PyUnicode_InternImmortal().
Later, the feature was added to the PyUnicodeObject type, new PyUnicode_InternImmortal() function:
Since Python 3.10, (mortal) interned strings are cleared at Python exit in Py_Finalize(). It avoids leaking memory when Python is embedded in an application: bpo-1635741.
PyUnicode_InternImmortal() is not used in the Python standard library. I propose to start deprecating the function and remove it in Python 3.12 (PEP-387 requires a deprecation for 2 releases). In Python 3.10, calling the function will emit a DeprecationWarning at runtime.
Note: PyString_InternImmortal() (for bytes strings) has been removed from Python 3.0.
2 similar comments
I cannot find "PyUnicode_InternImmortal" pattern in the source code of the PyPI top 5000 projects (December 1, 2021).
I only found a false positive in frozendict-2.1.1:
frozendict/src/3_10/cpython_src/Include/unicodeobject.h: // PyUnicode_InternImmortal() is deprecated since Python 3.10
These are copies of the Python unicodeobject.h header files, but the PyUnicode_InternImmortal() function is not called by frozendict.
I used my download_pypi_top.py and search_pypi_top.py tools which can be found at:
Remove the PyUnicode_InternImmortal() function and the SSTATE_INTERNED_IMMORTAL macro. The PyUnicode_InternImmortal() function is still exported in the stable ABI. The function is removed from the API. PyASCIIObject.state.interned size is now a single bit, rather than 2 bits. Keep SSTATE_NOT_INTERNED and SSTATE_INTERNED_MORTAL macros for backward compatibility, but no longer use them internally since the interned member is now a single bit and so can only have two values (interned or not interned). Update stats of _PyUnicode_ClearInterned().