[Python-Dev] Scope object (Re: nonlocals() function?)

Reid Kleckner rnk at mit.edu
Tue Apr 6 04:06:10 CEST 2010


On Mon, Apr 5, 2010 at 7:35 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> If you can prove that making locals() (or its replacement) writable doesn't
> complicate the interpreter core too much, then why not. Otherwise -1 :-)

I think writable locals would significantly complicate the job of
people trying to optimize Python.  The current situation is that so
long as a code object is compiled with certain flags and avoids using
exec, then it is impossible to indirectly modify locals in a call
frame without resorting to compiled code that mucks with the frame
directly.  It was very easy for us to check for these conditions, and
if they were met, emit faster code.

Collin implemented/optimized local variable access for unladen, so he
would know more than I.

If I remember correctly, the exec statement is going away in py3k, and
calling exec() with one argument can modify the local scope.
Therefore we'll probably have to do something more sophisticated
anyway.  :(

This would impact PyPy, Jython, and the other implementations, so I
would think twice about it.

Reid


More information about the Python-Dev mailing list