[Python-Dev] [PEP 558] thinking through locals() semantics
armin.rigo at gmail.com
Sun Jun 2 07:03:32 EDT 2019
On Wed, 29 May 2019 at 08:07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
> > Having a single locals() call de-optimize an entire function would be
> > far from ideal.
> I don't see what would be so bad about that. The vast majority
> of functions have no need for locals().
You have the occasional big function that benefits a lot from being
JIT-compiled but which contains ``.format(**locals())``. That occurs
in practice, and that's why PyPy is happy that there is a difference
between ``locals()`` and ``sys._getframe().f_locals``. PyPy could be
made to support the full mutable view, but that's extra work that
isn't done so far and is a bit unlikely to occur at this point. It
also raises the significantly the efforts for other JIT
implementations of Python if they have to support a full-featured
``locals()``; supporting ``_getframe().f_locals`` is to some extent
optional, but supporting ``locals()`` is not.
More information about the Python-Dev