Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyUnicode_AsUnicode is deprecated, slated for removal in 3.12 #5149

Closed
mattip opened this issue Nov 25, 2022 · 4 comments
Closed

PyUnicode_AsUnicode is deprecated, slated for removal in 3.12 #5149

mattip opened this issue Nov 25, 2022 · 4 comments

Comments

@mattip
Copy link
Contributor

mattip commented Nov 25, 2022

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.

@da-woods
Copy link
Contributor

I'm not convinced that this is a huge issue. Essentially this conversion function only applies for pointers defined as Py_UNICODE*. If any user code uses those then it'll probably become obsolete anyway and it's not our fault.

So really the question is "should we remove the test, change the test, or only run it on supported versions"?

@da-woods
Copy link
Contributor

In terms of the type conversion, I think we should just add a warning to Cython when people try to use it saying "type conversion from Python objects to Py_UNICODE* will only work on versions of Python that provide Py_UNICODE APIs. These are scheduled for removal in Python 3.12" or something similar. I don't think Cython is obliged to find workarounds beyond that.

@scoder scoder added this to the 3.0 milestone Nov 26, 2022
@scoder
Copy link
Contributor

scoder commented Nov 26, 2022

only run it on supported versions

This.

add a warning to Cython

Sounds good, too, although not visible by default, as we usually do. Now that there is an actual removal, it's good to warn about it, but people who use it probably know what they're doing at some point and don't need the warning any more, even if they keep their code around for supported Python versions.

@mattip
Copy link
Contributor Author

mattip commented Aug 15, 2023

Closing, although I never found a good place to add a warning. Please reopen if that should be part of this issue.

@mattip mattip closed this as completed Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants