PyEval_GetLocals and unreferenced variables

Ian Kelly ian.g.kelly at gmail.com
Thu Dec 4 10:42:09 EST 2014


On Wed, Dec 3, 2014 at 5:28 AM, Gregory Ewing <greg.ewing at canterbury.ac.nz>
wrote:
>
> Kasper Peeters wrote:
>>
>> That may have been the design plan, but in Python 2.7.6, I definitely
>> am able to inject locals via PyEval_GetLocals() and have them be visible
>> both from the C and Python side;
>
> What seems to be happening is that the dict created by
> PyEval_GetLocals() is kept around, so you can change it
> and have the changes be visible through locals() in
> Python.

That the dict is cached is an implementation detail. It's not advisable to
rely upon this, and as stated in the Python docs, the locals dict should
not be modified.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141204/e4e5bef5/attachment.html>


More information about the Python-list mailing list