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

Cesare Di Mauro cesare.di.mauro at gmail.com
Tue Apr 6 12:03:54 CEST 2010


2010/4/6 Greg Ewing <greg.ewing at canterbury.ac.nz>

> Cesare Di Mauro wrote:
>
>  It will certainly. There's MUCH that can be optimized to let CPython
>> squeeze more performance from static analysis (even a gross one) on locals.
>>
>
> But can the existing locals() function be implemented in
> the face of such optimisations?
>
> If it can, then a "locals view" object shouldn't be too much
> harder.
>
> If it can't, then you have already given up full CPython
> compatibility.
>
> --
> Greg


A read-only locals view can be a good comprise, because at least the first
example I showed can be approached well.

For the second example, there's no full compatibility with the current
CPython implementation.

But implementations can change over the time: we can clearly define that on
future CPython versions no assumptions must be made about locals "usage",
and in general about instructions generation.
The most important thing is that the function f() does what is called to do:
return the numeric constant 3.

This gives us the opportunity to schedule more efficient optimizations,
without losing generality about the language (only some weird tricks will
not be supported).

Cesare
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100406/8d0c603f/attachment.html>


More information about the Python-Dev mailing list