PEP 756 – [C API] Add PyUnicode_Export() and PyUnicode_Import() C functions

After looking some projects code, I think PyUnicode_Import is not worth enough.

They use PyUnicode_*_DATA() APIs for on-the-fly conversion from utf8 or utf16. But PyUnicode_Import() requires temporary buffer.

We already have PyUnicode_FromStringAndSize(), PyUnicode_DecodeUTF8/16/32() in stable API.
We can optimize and promote them instead of PyUnicode_New() + PyUnicode_*_DATA().

By the way, we have no-op PyUnicode_READY(). How about recommend (or require) calling it after PyUnicode_New() in the Python/C API reference? It will help PyPy, and future CPython.

(previous discussion about un-deprecate PyUnicode_READY()) Un-deprecate PyUnicode_READY() for future Unicode improvement

1 Like