[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
> > 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.
> Python-Dev mailing list
> Python-Dev at python.org
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev