New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate immortal interned strings: PyUnicode_InternImmortal() #85858
Comments
Python has the concept of "immortal" interned strings: PyUnicode_InternImmortal(). The feature was first introduced in the Python 2 "str" (bytes) type, bpo-576101 (commit 45ec02a). New PyString_InternImmortal() function. commit 45ec02a
Later, the feature was added to the PyUnicodeObject type, new PyUnicode_InternImmortal() function: commit 1680713
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. commit 666ecfb
-- 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. |
+1 |
2 similar comments
+1 |
+1 |
I proposed PR 22486 to deprecate the function. |
The function is now deprecated. Thanks for the review INADA-san, I close the issue. Let's meet in Python 3.12 to remove it ;-) |
For the record, I noticed PyUnicode_InternImmortal() is a stable ABI. We may need to keep the function to avoid dynamic link errors. |
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().
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
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: