Skip to content

PyUnicode_AsUnicode is deprecated, slated for removal in 3.12 #5149

@mattip

Description

@mattip

A call to PyUnicode_AsUnicode exposes the PyUnicodeObject.wstr field. This is removed in 3.12. The documentation says it is deprecated since 3.3, and it was removed in python/cpython#92537. This will require a workaround for this code

#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode

which is used here

self.from_py_function = "__Pyx_PyUnicode_AsUnicode"

I ran up against this in the py_unicode_strings tests when it uses a unicode object in a call to a cdef function with this signature cdef assert_Py_UNICODE_equal(const Py_UNICODE* u1, const Py_UNICODE* u2)

assert_Py_UNICODE_equal(uwide_literal, <Py_UNICODE*>c_pu_wide_literal)
.

The code might be hard to replace 1:1 since there is no longer a safe way to access the underlying PyUnicodeObject internal buffer, the remaining interfaces all need to deal with freeing the buffer when done with it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions