Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Open
Labels
3.13bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
I've constructed a sneaky way to break the remove_globals() optimization, by executing a code object in two different globals dicts. (Credit goes to @brandtbucher who started the conversation about this topic, though this particular example is mine.)
Take this code:
src="""def f(): global x def inner(i): a = 1 for _ in range(100): a = x + i return a return innerfunc = f()"""co=compile(src, __file__, "exec") ns1={"x": 1000} eval(co, ns1) func1=ns1["func"] foriinrange(1000): x=func1(i) print(x) ns2={"x": 2000} eval(co, ns2) func2=ns2["func"] foriinrange(1000): x=func2(i) print(x)This should print
1999 2999 (try it with Python 3.12, or Python 3.13 without JIT or -Xuops).
However with current main (EDIT: when using JIT or -Xuops) it prints
1999 1999 :-(
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error