On Tue, May 28, 2019 at 5:25 PM Greg Ewing <greg.ew...@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/>
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to