-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: Make org.jpy.PyLib.getCurrentLocals/Globals work for Python 3.13 #164
fix: Make org.jpy.PyLib.getCurrentLocals/Globals work for Python 3.13 #164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a good change. Should we prefer to instead increment locals for python <= 3.12, and always XDECREF? At least from the PEPs example of migrating PyEval_GetLocals
, it seems like incrementing the ref may be the more canonical approach?
locals = PyEval_GetLocals();
if (locals == NULL) {
goto error_handler;
}
Py_INCREF(locals);
to
locals = PyEval_GetFrameLocals();
if (locals == NULL) {
goto error_handler;
}
I wasn't very comfortable with the existing pattern (use borrowed ref) on globals/locals either, but it wasn't critical when GIL guarantees the thread-safetly. Now with free-threaded Python is just around the corner it is time to use the correct pattern for borrowed refs. |
Python 3.13.0rc1 includes PEP667 (https://peps.python.org/pep-0667) and it made PyEval_GetLocals() no longer behave the same way as in Python 3.12 and older, which could be a bug to report to the cpython team but probably not worth it as it is marked as deprecated together with PyEval_GetGlobals().