-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
gh-141004: Document unstable executable kind macros in pyframe.h
#143490
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
base: main
Are you sure you want to change the base?
Changes from all commits
1efbe41
4572008
54495a2
e8097b1
9c1492f
a0b1951
927383b
e51340a
3fafd77
45e9a6d
43e9c9f
efe7161
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -250,3 +250,62 @@ Unless using :pep:`523`, you will not need this. | |
| .. versionadded:: 3.12 | ||
|
|
||
|
|
||
| .. c:type:: PyUnstable_ExecutableKinds | ||
|
|
||
| An array of executable kinds (executor types) for frames, used for internal | ||
| debugging and tracing. | ||
|
|
||
| Tools like debuggers and profilers can use this to identify the type of execution | ||
| context associated with a frame (For example: to filter out internal frames). | ||
| The entries are indexed by the following constants: | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
| :widths: auto | ||
|
|
||
| * - Constant | ||
| - Description | ||
| * - .. c:macro:: PyUnstable_EXECUTABLE_KIND_SKIP | ||
| - The frame is internal (For example: inlined) and should be skipped by tools. | ||
| * - .. c:macro:: PyUnstable_EXECUTABLE_KIND_PY_FUNCTION | ||
| - The frame corresponds to a standard Python function. | ||
|
|
||
| Example usage: | ||
|
|
||
| .. code-block:: c | ||
|
|
||
| int kind = PyUnstable_Frame_GetExecutableKind(frame); | ||
|
|
||
| if (kind == PyUnstable_EXECUTABLE_KIND_SKIP) { | ||
| continue; | ||
| } | ||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. c:macro:: PyUnstable_EXECUTABLE_KIND_PY_FUNCTION | ||
|
|
||
| Index for the "Python function" kind in ``PyUnstable_ExecutableKinds``. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These should be links via |
||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. c:macro:: PyUnstable_EXECUTABLE_KIND_BUILTIN_FUNCTION | ||
|
|
||
| Index for the "built-in function" kind in ``PyUnstable_ExecutableKinds``. | ||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. c:macro:: PyUnstable_EXECUTABLE_KIND_METHOD_DESCRIPTOR | ||
|
|
||
| Index for the "method descriptor" kind in ``PyUnstable_ExecutableKinds``. | ||
|
|
||
| .. versionadded:: 3.13 | ||
|
|
||
|
|
||
| .. c:macro:: PyUnstable_EXECUTABLE_KINDS | ||
|
|
||
| The number of entries in ``PyUnstable_ExecutableKinds``. | ||
|
|
||
| .. versionadded:: 3.13 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test emits a DeprecationWarning:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}, | ||
|
|
@@ -131,4 +150,3 @@ _PyTestCapi_Init_Frame(PyObject *m) | |
| { | ||
| return PyModule_AddFunctions(m, test_methods); | ||
| } | ||
|
|
||
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.
What is
kind? How do you get it?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.
@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?
Uh oh!
There was an error while loading. Please reload this page.
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.
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.