Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
pyframe fix 9-test
  • Loading branch information
Yashp002 committed Feb 6, 2026
commit efe716189e13e697745a2a12a65a3e40ef95ea48
2 changes: 1 addition & 1 deletion Doc/c-api/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ Unless using :pep:`523`, you will not need this.

.. code-block:: c

int kind = PyUnstable_Frame_GetExecutableKind(frame)
int kind = PyUnstable_Frame_GetExecutableKind(frame);

if (kind == PyUnstable_EXECUTABLE_KIND_SKIP) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is kind? How do you get it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@encukou kind here refers to the executable kind field stored in the frame's executor (e.g. _PyFrame_GetExecutableKind(frame))
Do you think it's better to explicitly show _PyFrame_GetExecutableKind (if exposed), or should I just remove the example block to avoid confusion?

Copy link
Copy Markdown
Member

@encukou encukou Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, explicitly show your _PyFrame_GetExecutableKind. We'll also need to make it public (or at least unstable) if we want users to use it.

continue;
Expand Down
1 change: 1 addition & 0 deletions Include/cpython/frameobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ PyAPI_FUNC(void) PyFrame_LocalsToFast(PyFrameObject *, int);
* obsolete or outdated. */

PyAPI_FUNC(int) _PyFrame_IsEntryFrame(PyFrameObject *frame);
PyAPI_FUNC(int) PyUnstable_Frame_GetExecutableKind(PyFrameObject *frame);

PyAPI_FUNC(int) PyFrame_FastToLocalsWithError(PyFrameObject *f);
PyAPI_FUNC(void) PyFrame_FastToLocals(PyFrameObject *);
Expand Down
20 changes: 19 additions & 1 deletion Modules/_testcapi/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,26 @@ frame_getvarstring(PyObject *self, PyObject *args)
}


static PyObject *
test_my_doc_example(PyObject *self, PyObject *arg)
{
PyFrameObject *frame = (PyFrameObject *)PyEval_GetFrame();
if (frame == NULL) {
Py_RETURN_NONE;
}

int kind = PyUnstable_Frame_GetExecutableKind(frame);

if (kind == PyUnstable_EXECUTABLE_KIND_SKIP) {
return PyLong_FromLong(kind);
}

return PyLong_FromLong(kind);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test emits a DeprecationWarning:

ERROR: test_my_doc_example (test.test_capi.test_misc.Test_testcapi.test_my_doc_example)
----------------------------------------------------------------------
DeprecationWarning: It is deprecated to return a value that is not None from a test case (<built-in function test_my_doc_example> returned 'int')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner Honestly, i think im a little stuck on this issue, could you help?

}


static PyMethodDef test_methods[] = {
{"test_my_doc_example", test_my_doc_example, METH_NOARGS, NULL},
{"frame_getlocals", frame_getlocals, METH_O, NULL},
{"frame_getglobals", frame_getglobals, METH_O, NULL},
{"frame_getgenerator", frame_getgenerator, METH_O, NULL},
Expand All @@ -131,4 +150,3 @@ _PyTestCapi_Init_Frame(PyObject *m)
{
return PyModule_AddFunctions(m, test_methods);
}

20 changes: 20 additions & 0 deletions Python/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,23 @@ const PyTypeObject *const PyUnstable_ExecutableKinds[PyUnstable_EXECUTABLE_KINDS
[PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR] = &PyMethodDescr_Type,
[PyUnstable_EXECUTABLE_KINDS] = NULL,
};

PyAPI_FUNC(int)
PyUnstable_Frame_GetExecutableKind(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;
}
Loading