On Fri, Feb 25, 2022 at 1:48 PM Marc-Andre Lemburg mal@egenix.com wrote:
On 25.02.2022 13:15, Victor Stinner wrote:
Hi,
tl; dr the C API of PyFrameObject changed. If you have issues, please speak up!
I moved the PyFrameObject structure to the internal C API headers. You should now use the public C API to access its members:
f_back
: use :c:func:PyFrame_GetBack
.You only mention C APIs, but inspection tools are often written in Python. How can they access and walk the frames on the stack ?
Are these members still available as Python attributes of the frame objects ?
As far as I know, frame object members which were available on Python 3.10 are still available in Python 3.11 using the Python API. For example, reading "frame.f_back" in Python remains perfectly fine.
That's why the What's New in Python 3.11 document now recommends to simply use PyObject_GetAttrString(): use the Python API from C :-)
There are 8 frame members accessible in Python. They are listed in the inspect doc: https://docs.python.org/dev/library/inspect.html
- f_back
- f_builtins
- f_code
- f_globals
- f_lasti
- f_lineno
- f_locals
- f_trace
In fact, there are two more attributes which are not documented. I don't know if it's made on purpose:
- f_trace_lines (can be modified)
- f_trace_opcodes (can be modified)
Victor
Night gathers, and now my watch begins. It shall not end until my death.