We have some unstable APIs related to frame executables. We were looking into documenting them in #143490. These are defined at the bottom of frame.c:
| const PyTypeObject *const PyUnstable_ExecutableKinds[PyUnstable_EXECUTABLE_KINDS+1] = { | |
| [PyUnstable_EXECUTABLE_KIND_SKIP] = &_PyNone_Type, | |
| [PyUnstable_EXECUTABLE_KIND_PY_FUNCTION] = &PyCode_Type, | |
| [PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION] = &PyMethod_Type, | |
| [PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR] = &PyMethodDescr_Type, | |
| [PyUnstable_EXECUTABLE_KINDS] = NULL, | |
| }; |
The idea is that users can use these to determine the type of f_executable without accessing it -- but it seems we forgot to add an API to actually get one of the PyUnstable_EXECUTABLE_KIND* macros from a frame object! That means the only way to an entry out of PyUnstable_ExecutableKinds is to know the type in advance, like this:
int get_executable_kind(PyFrameObject *frame) { _PyInterpreterFrame *f = frame->f_frame; PyObject *exec = PyStackRef_AsPyObjectBorrow(f->f_executable); if (PyCode_Check(exec)) { return PyUnstable_EXECUTABLE_KIND_PY_FUNCTION; } if (PyMethod_Check(exec)) { return PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION; } if (Py_IS_TYPE(exec, &PyMethodDescr_Type)) { return PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR; } return PyUnstable_EXECUTABLE_KIND_SKIP; }
But, if you already know the type, then you have no reason to access PyUnstable_ExecutableKinds! For the future, let's decide on one of two options:
- If this is still intended to be useful, then let's add the
get_executable_kindfunction described above as an unstable C API. - Otherwise, let's just remove this in 3.16.
cc @markshannon (author of #105727, where these were added), @encukou
Linked PRs
- gh-152105: Remove docs snippet that uses internal C API #155122
- [3.13] gh-152105: Remove docs snippet that uses internal C API (GH-155122) #155240
- [3.15] gh-152105: Remove docs snippet that uses internal C API (GH-155122) #155241
- [3.14] gh-152105: Remove docs snippet that uses internal C API (GH-155122) #155242
- gh-152105: Remove PyUnstable_ExecutableKinds and related macros #155244