Skip to content

Commit 3e2aad2

Browse files
Xmaderzollqir
andauthored
feat: add back the ability to mutate parent scope variables with pm.exec/eval
Co-authored-by: Caleb Aikens <[email protected]>
1 parent c4d9405 commit 3e2aad2

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

python/pythonmonkey/require.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@
8484
globalThis.python.stderr.read = lambda n: sys.stderr.read(n)
8585
# Python 3.13 dramatically changed how the namespace in `exec`/`eval` works
8686
# See https://docs.python.org/3.13/whatsnew/3.13.html#defined-mutation-semantics-for-locals
87-
_locals = {} # keep the local variables inside `eval`/`exec` to a dict
88-
globalThis.python.eval = lambda x: eval(x, None, _locals)
89-
globalThis.python.exec = lambda x: exec(x, None, _locals)
90-
globalThis.python.getenv = os.getenv
87+
globalThis.python.eval = lambda x: eval(x, None, sys._getframe(1).f_locals)
88+
globalThis.python.exec = lambda x: exec(x, None, sys._getframe(1).f_locals)
9189
globalThis.python.paths = sys.path
9290

9391
globalThis.python.exit = pm.eval("""'use strict';

0 commit comments

Comments
 (0)