This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Henry Schreiner, Mark.Shannon, Skylion007, eric.snow, gregory.p.smith, pablogsal, terry.reedy, vstinner
Date 2022-02-07.16:15:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Example of C code that I added to _testcapi:
static PyObject *
get_caller_locals(PyObject *self, PyObject *Py_UNUSED(args))
    PyFrameObject *frame = PyThreadState_GetFrame(PyThreadState_Get());
    if (frame == NULL) {
    return PyObject_GetAttrString(frame, "f_locals");

Python example:
import _testcapi

def f():
    x = 1
    y = 2


Output on Python 3.11:
{'x': 1, 'y': 2}

=> it just works.

A PyFrameObject is a regular Python object, you can use functions like PyObject_GetAttrString().

Maybe I missed something, correct me if I'm wrong.
Date User Action Args
2022-02-07 16:15:32vstinnersetrecipients: + vstinner, terry.reedy, gregory.p.smith, Mark.Shannon, eric.snow, Henry Schreiner, pablogsal, Skylion007
2022-02-07 16:15:32vstinnersetmessageid: <>
2022-02-07 16:15:32vstinnerlinkissue46166 messages
2022-02-07 16:15:32vstinnercreate