[Python-Dev] Whatever happened to 'nonlocal x = y'?

Guido van Rossum guido at python.org
Fri Jan 5 14:07:17 EST 2018

Yeah, but I've changed my mind on this -- I think it's needless added
complexity that helps save one line of code in very few use cases. And you
don't really think the PEP endorses `nonlocal foo += 1` do you?

On Fri, Jan 5, 2018 at 10:48 AM, Random832 <random832 at fastmail.com> wrote:

> On Fri, Jan 5, 2018, at 10:47, Guido van Rossum wrote:
> > I don't recall (though someone with more time might find the discussion
> in
> > the archives or on the tracker). It was never implemented and I think it
> > shouldn't be. So we might as well update the PEP. It wouldn't be
> > particularly useful, since (by definition) the function that declares the
> > nonlocal variable is not its owner, and hence it's unlikely to make sense
> > to initialize it here. The same reasoning applies to global BTW.
> I'm not so sure...
> The only situation in which you're *required* to declare a nonlocal/global
> variable, after all, is if you intend to assign it - a name that you never
> assign is presumed to be non-local. The description in the PEP also applies
> to augmented assignments, and "global some_counter; some_counter += 1" is
> certainly a pattern I've needed in the past.
> The PEP also quotes you as endorsing this for global.
> https://mail.python.org/pipermail/python-3000/2006-November/004166.html
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> guido%40python.org

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180105/70974bf3/attachment.html>

More information about the Python-Dev mailing list