[Python-ideas] Explicit variable capture list

Serhiy Storchaka storchaka at gmail.com
Tue Jan 19 15:24:37 EST 2016


On 19.01.16 18:47, Guido van Rossum wrote:
> I think it's reasonable to divert this discussion to "value capture".
> Not sure if that's the usual terminology, but the idea should be that a
> reference to the value is captured, rather than (as Python normally does
> with closures) a reference to the variable (implemented as something
> called a "cell").
>
> (However let's please not consider whether the value should be copied or
> deep-copied. Just capture the object reference at the point the capture
> is executed.)
>
> The best syntax for such capture remains to be seen. ("Capture" seems to
> universally make people think of "variable capture" which is the
> opposite of what we want here.)

A number of variants of more powerful syntax were proposed in [1]. In 
neighbour topic Scott Sanderson had pointed to the asconstants decorator 
in codetransformer [2] that patches the code object by substituting a 
references to the variable with a reference to the constant. Ryan 
Gonzalez provided other implementation of similar decorator [3].

May be this feature doesn't need new syntax, but just new decorator in 
the stdlib.

[1] http://comments.gmane.org/gmane.comp.python.ideas/37047
[2] http://permalink.gmane.org/gmane.comp.python.ideas/36958
[3] http://permalink.gmane.org/gmane.comp.python.ideas/37058




More information about the Python-ideas mailing list