osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] [SPAM?] Re: PEP 558: Defined semantics for locals()


On Tue, May 28, 2019 at 5:25 PM Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Terry Reedy wrote:
> > I believe that the situation is or can be thought of as this: there is
> > exactly 1 function locals dict.  Initially, it is empty and inaccessible
> > (unusable) from code.  Each locals() call updates the dict to a current
> > snapshot and returns it.
>
> Yes, I understand *what's* happening, but not *why* it was designed
> that way. Would it really be prohibitively expensive to create a
> fresh dict each time?
>

No. But it would be inconsistent with the behavior at module level.

FWIW I am leaning more and more to the [proxy] model, where locals() and
frame.f_locals are the same object, which *proxies* the fast locals and
cells. That only has one downside: it no longer returns a dict, but merely
a MutableMapping. But why would code care about the difference? (There used
to be some relevant builtins that took dicts but not general
MutableMappings -- but that has been fixed long ago.)

-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him/his **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20190528/d1775d35/attachment.html>