gh-145055: Accept frozendict for globals in exec() and eval() (#145072)

This commit is contained in:
Victor Stinner 2026-03-05 12:35:43 +01:00 committed by GitHub
parent c8aa8de9a5
commit c0ecf211b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 66 additions and 22 deletions

View file

@ -1348,8 +1348,9 @@ static PyObject *
run_eval_code_obj(PyThreadState *tstate, PyCodeObject *co, PyObject *globals, PyObject *locals)
{
/* Set globals['__builtins__'] if it doesn't exist */
if (!globals || !PyDict_Check(globals)) {
PyErr_SetString(PyExc_SystemError, "globals must be a real dict");
if (!globals || !PyAnyDict_Check(globals)) {
PyErr_SetString(PyExc_SystemError,
"globals must be a real dict or a real frozendict");
return NULL;
}
int has_builtins = PyDict_ContainsString(globals, "__builtins__");