for historical reason. It is no longer allowed.
(Contributed by Victor Stinner in :issue:`40839`.)
+* ``PyUnicode_FromUnicode(NULL, size)`` and ``PyUnicode_FromStringAndSize(NULL, size)``
+ raise ``DeprecationWarning`` now. Use :c:func:`PyUnicode_New` to allocate
+ Unicode object without initial data.
+ (Contributed by Inada Naoki in :issue:`36346`.)
+
Removed
-------
import _testcapi
u = '𝖀𝖓𝖎𝖈𝖔𝖉𝖊'
self.assertTrue(u.isidentifier())
- self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier())
+ with support.check_warnings():
+ warnings.simplefilter('ignore', DeprecationWarning)
+ self.assertTrue(_testcapi.unicode_legacy_string(u).isidentifier())
def test_isprintable(self):
self.assertTrue("".isprintable())
--- /dev/null
+Raises DeprecationWarning for ``PyUnicode_FromUnicode(NULL, size)`` and
+``PyUnicode_FromStringAndSize(NULL, size)`` with ``size > 0``.
PyObject *
PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
{
- if (u == NULL)
+ if (u == NULL) {
+ if (size > 0) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PyUnicode_FromUnicode(NULL, size) is deprecated; "
+ "use PyUnicode_New() instead", 1) < 0) {
+ return NULL;
+ }
+ }
return (PyObject*)_PyUnicode_New(size);
+ }
if (size < 0) {
PyErr_BadInternalCall();
"Negative size passed to PyUnicode_FromStringAndSize");
return NULL;
}
- if (u != NULL)
+ if (u != NULL) {
return PyUnicode_DecodeUTF8Stateful(u, size, NULL, NULL);
- else
+ }
+ else {
+ if (size > 0) {
+ if (PyErr_WarnEx(PyExc_DeprecationWarning,
+ "PyUnicode_FromStringAndSize(NULL, size) is deprecated; "
+ "use PyUnicode_New() instead", 1) < 0) {
+ return NULL;
+ }
+ }
return (PyObject *)_PyUnicode_New(size);
+ }
}
PyObject *