Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
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:
importtextwrapdeffoo_func():a=1b=2foo_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