[Python-Dev] frame.f_locals is writable (original) (raw)

Shane Holloway (IEEE) shane.holloway at ieee.org
Thu Jan 13 21:42:58 CET 2005


For a little background, I'm working on making an edit and continue support in python a little more robust. So, in replacing references to unmodifiable types like tuples and bound-methods (instance or class), I iterate over gc.get_referrers.

So, I'm working on frame types, and wrote this code::

 def replaceFrame(self, ref, oldValue, newValue):
     for name, value in ref.f_locals.items():
         if value is oldValue:
             ref.f_locals[name] = newValue
             assert ref.f_locals[name] is newValue

But unfortunately, the assert fires. f_locals is writable, but not modifiable. I did a bit of searching on Google Groups, and found references to a desire for smalltalk like "swap" functionality using a similar approach, but no further ideas or solutions.

While I am full well expecting the smack of "don't do that", this functionality would be very useful for debugging long-running applications. Is this possible to implement in CPython and ports? Is there an optimization reason to not do this?

At worst, if this isn't possible, direct references in the stack will be wrong above the reload call, and corrected on the invocation of the function. This is a subtle issue with reloading code, and can be documented. And at best there is an effective way to replace it, the system can be changed to a consistent state even in the stack, and I can rejoice. Even if I have to wait until 2.5. ;)

Thanks for your time! -Shane Holloway



More information about the Python-Dev mailing list