"""
self._check_in_scopes(code, {"value": [1, None]})
+ def test_frame_locals(self):
+ code = """
+ val = [sys._getframe().f_locals for a in [0]][0]["a"]
+ """
+ import sys
+ self._check_in_scopes(code, {"val": 0}, ns={"sys": sys})
+
__test__ = {'doctests' : doctests}
static PyObject *
frame_getlocals(PyFrameObject *f, void *closure)
{
- if (PyFrame_FastToLocalsWithError(f) < 0)
+ if (f == NULL) {
+ PyErr_BadInternalCall();
return NULL;
- PyObject *locals = f->f_frame->f_locals;
- return Py_NewRef(locals);
+ }
+ assert(!_PyFrame_IsIncomplete(f->f_frame));
+ PyObject *locals = _PyFrame_GetLocals(f->f_frame, 1);
+ if (locals) {
+ f->f_fast_as_locals = 1;
+ }
+ return locals;
}
int
int
PyFrame_FastToLocalsWithError(PyFrameObject *f)
{
- assert(!_PyFrame_IsIncomplete(f->f_frame));
if (f == NULL) {
PyErr_BadInternalCall();
return -1;
}
+ assert(!_PyFrame_IsIncomplete(f->f_frame));
int err = _PyFrame_FastToLocalsWithError(f->f_frame);
if (err == 0) {
f->f_fast_as_locals = 1;