classification
Title: exec function fails to properly assign scope to dict like object
Type: behavior Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, btomtom5
Priority: normal Keywords:

Created on 2016-03-14 18:31 by btomtom5, last changed 2016-03-14 19:54 by belopolsky. This issue is now closed.

Messages (2)
msg261774 - (view) Author: Brian Tom (btomtom5) Date: 2016-03-14 18:32
http://stackoverflow.com/questions/35993869/passing-a-dictionary-like-object-to-exec-instead-of-dict-object-changes-scope-of
msg261776 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2016-03-14 19:54
The SO example works for me with Python 3.5.1:

Python 3.5.1 (default, Mar  8 2016, 12:33:47)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> global_function = """
... x = "Hello World"
... def print_global_x():
...     print(x)
... print_global_x()
... """
>>> import builtins
>>> class TestEnvironment(dict):
...     def __init__(self, *args):
...         super().__init__(*args)
...
>>> global_env = TestEnvironment()
>>> global_env['__builtins__'] = builtins
>>> exec(global_function, global_env)
Hello World

btomtom5 - a bug report that consists only of an SO link is likely to be treated as spam by many issue tracker subscribers.  In the future, please try to make your reports self-contained.
History
Date User Action Args
2016-03-14 19:54:32belopolskysetstage: resolved
2016-03-14 19:54:18belopolskysetstatus: open -> closed

nosy: + belopolsky
messages: + msg261776

resolution: works for me
2016-03-14 18:32:58btomtom5setmessages: + msg261774
2016-03-14 18:31:43btomtom5create