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

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Apr 6 11:13:08 CEST 2010


Reid Kleckner wrote:

> If I remember correctly, the exec statement is going away in py3k, and
> calling exec() with one argument can modify the local scope.

I've been kind of wondering what the deal is with exec in py3.
I always thought the reason for making exec a statement was so
that locals optimisation could be turned off in its presence,
so I'm not sure how py3 is getting away with making it a
function.

Anyhow, it seems to me that as long as locals() or whatever
might replace it is able to find the existing value of a local,
it should also be able to change that value, wherever it
happens to be stored.

I suppose that might fail if an optimiser decides to keep
multiple copies of a local for some reason, though.

But even if it has to be read-only, I still think a view object
would be a more py3ish way of handling locals() and the like.
You might only want access to a few locals, in which case
building a dict containing all of them would be wasteful.

-- 
Greg


-- 
Greg


More information about the Python-Dev mailing list