Open
Description
Bug report
Bug description:
When passing a code object to the eval (doc) builtin, I am observing that the locals dictionary is not always filled with the variables created inside of the code. For example:
import textwrap
def foo_func():
a = 1
b = 2
foo_str = compile(
textwrap.dedent("""\
a = 1
b = 2
"""
),
'<file>',
'exec',
)
glb = globals()
loc = {}
eval(foo_func.__code__, glb, loc)
print('foo_func', loc)
eval(foo_str, glb, loc)
print('foo_str', loc)
produces the output:
foo_func {}
foo_str {'a': 1, 'b': 2}
I would expect the output to be the same for both calls.
CPython versions tested on:
3.13
Operating systems tested on:
Linux, macOS