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_kind function 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
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:cpython/Python/frame.c
Lines 153 to 159 in 0fb82b4
The idea is that users can use these to determine the type of
f_executablewithout accessing it -- but it seems we forgot to add an API to actually get one of thePyUnstable_EXECUTABLE_KIND*macros from a frame object! That means the only way to an entry out ofPyUnstable_ExecutableKindsis to know the type in advance, like this: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:get_executable_kindfunction described above as an unstable C API.cc @markshannon (author of #105727, where these were added), @encukou