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 <random...@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@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)
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com