]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-135443: Sometimes Fall Back to __main__.__dict__ For Globals (gh-135491)
authorEric Snow <ericsnowcurrently@gmail.com>
Mon, 16 Jun 2025 23:34:19 +0000 (17:34 -0600)
committerGitHub <noreply@github.com>
Mon, 16 Jun 2025 23:34:19 +0000 (17:34 -0600)
commita450a0ddec7a2813fb4603f0df406fa33750654a
tree39733c6db9778d0936bd281a78488cd22bd292ec
parent68b7e1a6677d7a8fb47fbd28cb5d39a87217273c
gh-135443: Sometimes Fall Back to __main__.__dict__ For Globals (gh-135491)

For several builtin functions, we now fall back to __main__.__dict__ for the globals
when there is no current frame and _PyInterpreterState_IsRunningMain() returns
true.  This allows those functions to be run with Interpreter.call().

The affected builtins:

* exec()
* eval()
* globals()
* locals()
* vars()
* dir()

We take a similar approach with "stateless" functions, which don't use any
global variables.
Include/internal/pycore_ceval.h
Lib/test/test_interpreters/test_api.py
Objects/object.c
Python/bltinmodule.c
Python/ceval.c
Python/crossinterp_data_lookup.h
Python/import.c