Mar-27-2017, 12:22 PM
(Mar-27-2017, 10:11 AM)Skaperen Wrote: it doesn't have to be locals. it just has to be somewhere. if nothing else is added to to the space then there is the option to extract "misspelled" config options. but the global space gets stuff added so it is to be avoid if that option is to be used. my pyconf() function was intended to return a dictionary of what the config file set. so, the issue of how comprehensions are used is going to be used will be the same in a python format config file as in regular code. no big deal.
Isolation of executed code can be achieved just with globals parameter (globals parameter has nothing common with global scope (globals()) from where you use exec). And with regular import comprehensions would work, problem is with locals parameter enforcing "class definition execution".
>>> s = "boo=1" >>> config = {} >>> exec(s, config) >>> boo Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'boo' is not defined >>> config['boo'] 1