8000 gh-91248: Add PyFrame_GetVar() function by vstinner · Pull Request #95712 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-91248: Add PyFrame_GetVar() function #95712

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

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
gh-91248: Add PyFrame_GetVar() function
Add PyFrame_GetVar() and PyFrame_GetVarString() functions to get a
frame variable by its name.

Move PyFrameObject C API tests from test_capi to test_frame.
  • Loading branch information
vstinner committed Nov 4, 2022
commit d6c44ae979b2ae3f62bd8df365517a6acadc54bb
19 changes: 19 additions & 0 deletions Doc/c-api/frame.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ See also :ref:`Reflection <reflection>`.
.. versionadded:: 3.11


.. c:function:: PyObject* PyFrame_GetVar(PyFrameObject *frame, PyObject *name)

Get the variable *name* of *frame*.

* Return a :term:`strong reference` to the variable value on success.
* Raise :exc:`NameError` and return ``NULL`` if the variable does not exist.
* Raise an exception and return ``NULL`` on error.

.. versionadded:: 3.12


.. c:function:: PyObject* PyFrame_GetVarString(PyFrameObject *frame, const char *name)

Similar to :c:func:`PyFrame_GetVar`, but the variable name is a C string
encoded in UTF-8.

.. versionadded:: 3.12


.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)

Get the *frame*'s ``f_locals`` attribute (:class:`dict`).
Expand Down
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,10 @@ New Features
(Contributed by Carl Meyer in :gh:`91051`.)


* Add :c:func:`PyFrame_GetVar` and :c:func:`PyFrame_GetVarString` functions to
get a frame variable by its name.
(Contributed by Victor Stinner in :gh:`91248`.)

Porting to Python 3.12
----------------------

Expand Down
3 changes: 2 additions & 1 deletion Include/cpython/pyframe.h