[issue7083] locals() behaviour differs when tracing is in effect
Antoine Pitrou
report at bugs.python.org
Thu Oct 8 17:37:21 CEST 2009
Antoine Pitrou <pitrou at free.fr> added the comment:
The same is thing is true of the frame's f_locals attribute. This
attribute is a copy of the local variables in the frame, because the
internal storage of these variables is a raw C array for faster access.
This copy is only synchronized back when a tracing function returns, so
as to allow implementing a debugger.
>>> def f():
... a = 1
... l = sys._getframe().f_locals
... b = 2
... return l
...
>>> f()
{'a': 1}
The above optimization (raw C array for faster access of local
variables) is not done at the global scope, and therefore locals() at
that scope give you direct access to the variables' internal store
(which is, actually, the module's __dict__).
>>> import __main__
>>> __main__.__dict__ is locals()
True
----------
nosy: +pitrou
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7083>
_______________________________________
More information about the Python-bugs-list
mailing list