Le mar. 7 juil. 2020 à 17:21, Inada Naoki <songofaca...@gmail.com> a écrit :
> This PEP proposes to remove deprecated ``Py_UNICODE`` encoder APIs in
> Python 3.11:

Overall, I like the plan. IMHO 3.11 is a reasonable target version,
since on the top 4000 projects, only 2 are affected and it is easy to
fix them.


> Python 3.9
> ----------
>
> Add ``Py_DEPRECATED(3.3)`` to following APIs. This change is committed
> already [3]_. All other APIs have been marked ``Py_DEPRECATED(3.3)``
> already.
>
> * ``PyUnicode_EncodeDecimal()``
> * ``PyUnicode_TransformDecimalToASCII()``.
>
> Document all APIs as "will be removed in version 3.11".

I guess that if the release manager is not ok to add the two remaining
Py_DEPRECATED() warnings, they can be added to 3.10 instead.


> Make some private APIs public
>
> ``PyUnicode_EncodeUTF7()`` doesn't have public alternative APIs.
>
> Some APIs have alternative public APIs. But they are missing
> ``const char *errors`` or ``int byteorder`` parameters.

If needed, new functions can be added independently of this PEP.



> Using runtime warning
> ---------------------
>
> These APIs doesn't release GIL for now. Emitting a warning from
> such APIs is not safe. See this example.
>
> .. code-block::
>
>    PyObject *u = PyList_GET_ITEM(list, i);  // u is borrowed reference.
>    PyObject *b = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(u),
>            PyUnicode_GET_SIZE(u), NULL);
>    // Assumes u is still living reference.
>    PyObject *t = PyTuple_Pack(2, u, b);
>    Py_DECREF(b);
>    return t;
>
> If we emit Python warning from ``PyUnicode_EncodeUTF8()``, warning
> filters and other threads may change the ``list`` and ``u`` can be
> a dangling reference after ``PyUnicode_EncodeUTF8()`` returned.
>
> Additionally, since we are not changing behavior but removing C APIs,
> runtime ``DeprecationWarning`` might not helpful for Python
> developers. We should warn to extension developers instead.

DeprecationWarning is hidden by default: users would not be impacted.

I don't think that encoding functions are special enough to skip these
warnings. I think that it's reasonable to change the behavior on these
deprecated functions to emit a warning.

Victor
-- 
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
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/M523JOR2B36QYIWO4LMS4QPUDFF23E3T/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to