R. David Murray added the comment:

Do you mean that *modifying* locals() in the function scope is undefined 
behavior?  That makes sense, and is a documented limitation.

So we need to clarify the execfile/exec documentation to note that if called in 
anything other than the global scope, locals() will get used as the locals 
dictionary, and this will lead to undefined behavior if any operation is 
performed that updates the local namespace...and thus you are best recommend to 
always pass one or two dictionaries to execfile/exec, so that you *know* what 
is getting updated.

Although I have to say that the exec/execfile doing something that is specified 
to lead to undefined behavior smells like a bug.  (Not that we could fix it 
even if we agreed that it was, for backward compatibility reasons.)

----------
title: execfile/exec execution of class statement does not access locals() -> 
execfile/exec execution in other than global scope uses locals(), leading to 
undefined behavior

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16781>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to