-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error