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

Terry Reedy tjreedy at udel.edu
Sat May 25 14:12:14 EDT 2019


On 5/25/2019 10:36 AM, Guido van Rossum wrote:
> This looks great.

I agree.  I understand and have tried to explain normal operation 
multiple times.  The proposed new doc looks better than anything I ever 
wrote.  (I never even thought about locals() with tracing on.)  The 
improved clarity well justifies the increased space.

> I only have two nits with the text.
> 
> First, why is the snapshot called a "dynamic snapshot"? What exactly is 
> dynamic about it?

Good catch.  'snapshot' is from "At function scope (including for 
generators and coroutines), [locals()] returns a dynamic snapshot of the 
function's local variables and any nonlocal cell references."
'Dynamic' could be misunderstood to mean the function locals() snapshot 
always tracks the underlying function namespace.  The point of using the 
'snapshot' metaphor is that it does not.

The snapshot is 'dynamic' in that it can be changed, but the same is 
true of real photos.  But just as with real photos, changing the 
snapshot does not change the reality it represents (as explained in the 
next proposed sentence).  The 'snapshot' metaphor does not need 
'dynamic' and I think it works better without it.

> Second, you use the word "mapping" a lot. Would you mind changing that 
> to "mapping object" in most places? Especially in the phrase "each call 
> to ``locals()`` returns the *same* mapping". To me, without the word 
> "object" added, this *could* be interpreted as "a dict with the same 
> key/value pairs" (since "mapping" is also an abstract mathematical 
> concept describing anything that maps keys to values).

Agreed also.


-- 
Terry Jan Reedy



More information about the Python-Dev mailing list