I second a public api for _PyObject_Dump, but I think renaming it and making it public would be much better instead due to also using it to debug my C extensions.
Please add a public API for _PyObject_Dump. It's quite useful for debugging.
Is it really useful to add a public C API for that? Even if the API is deprecated, you can still use it in gdb/lldb and in your code. Even if later the function will be removed from the public C API, it would only be moved to the internal C API, not really removed.
It's also helpful for debugging extensions outside of CPython. I'd find debugging extensions to be a little bit harder if it were removed from the public headers without a replacement.
_PyLong_GCD(): call Python math.gcd() function
_PyLong_NumBits(): call Python int.bit_length() method
I would rather expose this as public. Why do we want to hide (under a slower interface) this from users? These functions are something common for all big ints libraries.
Makes sense in general, but please don't add just “use XYZ()” in the What's New. With any deprecation we should help people update code that starts raising warnings.
Definitely don't recommend PySlice_GetIndices() -- it's docs say “You probably do not want to use this function”; it's effectively been soft-deprecated since 2003.
I would rather expose this as public. Why do we want to hide (under a slower interface) this from users? These functions are something common for all big ints libraries.
I already proposed adding a public PyLong_GCD() function in #111139 but the idea got rejected.
I think deprecating the PEP 523 APIs would take a PEP with a better solution. There are a number of JITs that use these APIs despite being private and I think it would break too many things to remove them without a replacement. There was some discussion at PyCon US last year about a better frame evaluation API for JITs but I don't recall if anyone was planning on working on a PEP with a solution in mind.
For PEP 523 functions, _PyInterpreterState_GetEvalFrameFunc(), _PyInterpreterState_SetEvalFrameFunc() and _PyEval_EvalFrameDefault(), I think that public functions should be added to replace them: PyInterpreterState_GetEvalFrameFunc(), PyInterpreterState_SetEvalFrameFunc() and PyEval_EvalFrameDefault() (just remove the _ prefix).
I think that public functions should be added to replace them
That's certainly one solution, but I think there is more to be decided around what a public facing API for those should be. I'd say they should be considered separately and will almost certainly require more discussion.
I spent significant time on trying to promote the last private functions to the first-class public API category. It seems like remaining private functions are really in a grey area, not really internal, not really public, but in between. It's hard to argue to promote them as public functions. I'm not sure that it's worth it to spend more time on the remaining functions. Or maybe if the effort is continued, it should be on a case by case basis, by promoting a function or a small set of functions.
I close the issue. Thanks for helping me to look at these functions.
Activity
ZeroIntensity commented on Nov 5, 2025
Please add a public API for _PyObject_Dump. It's quite useful for debugging.
AraHaan commented on Nov 5, 2025
I second a public api for _PyObject_Dump, but I think renaming it and making it public would be much better instead due to also using it to debug my C extensions.
vstinner commented on Nov 5, 2025
Is it really useful to add a public C API for that? Even if the API is deprecated, you can still use it in gdb/lldb and in your code. Even if later the function will be removed from the public C API, it would only be moved to the internal C API, not really removed.
ZeroIntensity commented on Nov 5, 2025
It's also helpful for debugging extensions outside of CPython. I'd find debugging extensions to be a little bit harder if it were removed from the public headers without a replacement.
vstinner commented on Nov 5, 2025
Ok, I created #141070 to add PyObject_Dump().
skirpichev commented on Nov 5, 2025
I would rather expose this as public. Why do we want to hide (under a slower interface) this from users? These functions are something common for all big ints libraries.
encukou commented on Nov 6, 2025
Makes sense in general, but please don't add just “use XYZ()” in the What's New. With any deprecation we should help people update code that starts raising warnings.
Definitely don't recommend PySlice_GetIndices() -- it's docs say “You probably do not want to use this function”; it's effectively been soft-deprecated since 2003.
vstinner commented on Nov 6, 2025
I already proposed adding a public PyLong_GCD() function in #111139 but the idea got rejected.
emmatyping commented on Nov 7, 2025
I think deprecating the PEP 523 APIs would take a PEP with a better solution. There are a number of JITs that use these APIs despite being private and I think it would break too many things to remove them without a replacement. There was some discussion at PyCon US last year about a better frame evaluation API for JITs but I don't recall if anyone was planning on working on a PEP with a solution in mind.
vstinner commented on Nov 8, 2025
For PEP 523 functions, _PyInterpreterState_GetEvalFrameFunc(), _PyInterpreterState_SetEvalFrameFunc() and _PyEval_EvalFrameDefault(), I think that public functions should be added to replace them: PyInterpreterState_GetEvalFrameFunc(), PyInterpreterState_SetEvalFrameFunc() and PyEval_EvalFrameDefault() (just remove the _ prefix).
emmatyping commented on Nov 8, 2025
That's certainly one solution, but I think there is more to be decided around what a public facing API for those should be. I'd say they should be considered separately and will almost certainly require more discussion.
vstinner commented on Nov 13, 2025
I created #141518 for PEP 523 functions. We can start a discussion there.
vstinner commented on Dec 3, 2025
I created issue #142217 and PR #142221 to deprecate the 3 functions using the _Py_Identifier structure.
vstinner commented on May 29, 2026
I spent significant time on trying to promote the last private functions to the first-class public API category. It seems like remaining private functions are really in a grey area, not really internal, not really public, but in between. It's hard to argue to promote them as public functions. I'm not sure that it's worth it to spend more time on the remaining functions. Or maybe if the effort is continued, it should be on a case by case basis, by promoting a function or a small set of functions.
I close the issue. Thanks for helping me to look at these functions.