On Sun, Jun 28, 2020 at 11:24 PM Inada Naoki <songofaca...@gmail.com> wrote:
>
>
> So how about making them public, instead of undeprecate Py_UNICODE* encode 
> APIs?
>
> 1. Add PyUnicode_AsXXXBytes public APIs in Python 3.10.
>    Current private APIs can become macro (e.g. #define
> _PyUnicode_AsAsciiString PyUnicode_AsAsciiBytes),
>    or deprecated static inline function.
> 2. Remove Py_UNICODE* encode APIs in Python 3.12.
>

More aggressive idea: override current PyUnicode_EncodeXXX() apis.
Change from `Py_UNICODE *object` to `PyObject *unicode`.

This idea might look crazy.  But PyUnicode_EncodeXXX APIs are
deprecated for a long time, and there are only a few users.
I grepped from 3874 source packages in top 4000 downloaded packages.
(126 packages are wheel-only)

$ rg -w PyUnicode_EncodeASCII
Cython-0.29.20/Cython/Includes/cpython/unicode.pxd
424:    bytes PyUnicode_EncodeASCII(Py_UNICODE *s, Py_ssize_t size,
char *errors)

$ rg -w PyUnicode_EncodeLatin1
Cython-0.29.20/Cython/Includes/cpython/unicode.pxd
406:    bytes PyUnicode_EncodeLatin1(Py_UNICODE *s, Py_ssize_t size,
char *errors)

$ rg -w PyUnicode_EncodeUTF7
(no output)

$ rg -w PyUnicode_EncodeUTF8
subprocess32-3.5.4/_posixsubprocess_helpers.c
38:        return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),

pyodbc-4.0.30/src/params.cpp
1932:                        bytes = PyUnicode_EncodeUTF8(source, cb, "strict");

pyodbc-4.0.30/src/cnxninfo.cpp
45:    Object bytes(PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(p),
PyUnicode_GET_SIZE(p), 0));
50:    Object bytes(PyUnicode_Check(p) ?
PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(p), PyUnicode_GET_SIZE(p),
0) : 0);

Cython-0.29.20/Cython/Includes/cpython/unicode.pxd
304:    bytes PyUnicode_EncodeUTF8(Py_UNICODE *s, Py_ssize_t size, char *errors)

Note that subprocess32 is Python 2 only project.  Only pyodbc-4.0.30
use this API.
https://github.com/mkleehammer/pyodbc/blob/b4ea03220dd8243e452c91689bef34823b2f7d8f/src/params.cpp#L1926-L1942
https://github.com/mkleehammer/pyodbc/blob/master/src/cnxninfo.cpp#L45

Anyway, current PyUnicode_EncodeXXX APis are not used commonly.
I don't think it's worth enough to undeprecate.

Regards,

-- 
Inada Naoki  <songofaca...@gmail.com>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/SFZ64X5JIOERQYCGGAD63FLRTJ657WWM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to