[issue17546] rename type returned by locals() to livedict

Eric Snow report at bugs.python.org
Tue Mar 26 16:28:16 CET 2013


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 <report at bugs.python.org>
<http://bugs.python.org/issue17546>
_______________________________________


More information about the Python-bugs-list mailing list