Eric Snow added the comment:

So the problem you are having is that inside functions the dict returned by 
locals() does not get updated when the "current local symbol table" changes?  
Keep in mind that for modules and classes (the other two execution blocks), the 
dict returned by locals() does get updated.

This difference reflects that fact that, in CPython at least, the local 
execution namespace of a function call's stack frame is not stored in a 
dictionary.  When you call locals() in a function it is only making a copy of 
the frame's fast locals.  The fast locals never gets directly exposed except 
through normal name lookup/binding/deletion.  While technically possible, 
changing this simply isn't worth it.

The documentation already makes it clear that the dict returned by locals() 
represents the "current local symbol table" and that you should not expect 
changes to that dict to be reflected in the actual locals.  Are you 
recommending that it be more clear that the dict may be no more than a snapshot 
of the locals at the time locals() is called?

----------

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

Reply via email to