[Python-ideas] Explicit variable capture list

Guido van Rossum guido at python.org
Tue Jan 19 18:43:12 EST 2016


On Tue, Jan 19, 2016 at 12:24 PM, Serhiy Storchaka <storchaka at gmail.com>
wrote:
>
> 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.
>

Hmm... Using a decorator would mean that you'd probably have to add quotes
around the names of the variables whose values you want to capture, and
it'd require hacking the bytecode. That would mean that it'd only work for
CPython, and it'd not be a real part of the language. This feels like it
wants to be a language-level feature, like nonlocal.


> [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
>

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160119/8bcc5bc5/attachment.html>


More information about the Python-ideas mailing list