[Python-ideas] Explicit variable capture list

Michael Selik mike at selik.org
Wed Jan 20 18:56:00 EST 2016


On Wed, Jan 20, 2016 at 2:05 PM Yury Selivanov <yselivanov.ml at gmail.com>
wrote:

> On 2016-01-20 1:37 AM, Nick Coghlan wrote:
> > On 20 January 2016 at 10:38, Chris Angelico<rosuav at gmail.com>  wrote:
> > With that spelling:
> >
> >      def f(*, len=len):
> >           ...
> >
> > Would become:
> >
> >      def f():
> >          sharedlocal len=len
>
> FWIW I strongly believe that this feature (at least the
> "len=len"-like optimizations) should be implemented as an
> optimization in the interpreter.
>
> We already have "nonlocal" and "global".  Having a third
> modifier (such as sharedlocal, static, etc) will only
> introduce confusion and make Python less comprehensible.
>

If the purpose is to improve speed, it certainly feels like an interpreter
optimization. The other thread about adding ``ma_version`` to dicts might
be useful for quickening the global variable lookup.

If the purpose is to store the current global value, it might be reasonable
to add a language feature to make that more explicit. Beginners often
mistakenly think that default values are evaluated and assigned at
call-time instead of def-time. However, adding a new, more explicit
language feature wouldn't eliminate the current confusion. Instead we'd
have two ways to do it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160120/3e238b6d/attachment.html>


More information about the Python-ideas mailing list