gh-105340: include hidden fast-locals in locals() (#105715)

* gh-105340: include hidden fast-locals in locals()
This commit is contained in:
Carl Meyer 2023-07-05 17:05:02 -06:00 • committed by GitHub
parent 838406b4fc
commit 104d7b760f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 160 additions and 44 deletions

View file

@ -1690,13 +1690,15 @@ _dir_locals(void)
PyObject *names;
PyObject *locals;
locals = PyEval_GetLocals();
locals = _PyEval_GetFrameLocals();
if (locals == NULL)
return NULL;
names = PyMapping_Keys(locals);
if (!names)
Py_DECREF(locals);
if (!names) {
return NULL;
}
if (!PyList_Check(names)) {
PyErr_Format(PyExc_TypeError,
"dir(): expected keys() of locals to be a list, "
@ -1708,7 +1710,6 @@ _dir_locals(void)
Py_DECREF(names);
return NULL;
}
/* the locals don't need to be DECREF'd */
return names;
}