How about eval/exec take a new env argument that is a nested
dictionary whose outer level corresponds to locals, and which has a
__up__ value which is the next outer level environment dict. The
outermost level of the nested dictionary would correspond to the
global level?
I haven't given much thought to my suggested solution - I just didn't
want to leave a possible solution out. The major point is that there
seems to be no support for nonlocal in eval/exec (unless, trivially,
nonlocal==global).
- Paddy.
Right. That was and is Python's execution model.
Note that when you exec code, including a function call, the locals
passed is the local context in which the code is executed. It is not the
locals of any particular function called by the exec-ed code.
If you exec a function that is a closure, the closure or non-local
objects come with the function. A 'stack of dicts' has nothing to do
with how function and nested funcs operate.
--
Terry Jan Reedy
Thanks Terry.