On Fri, Jan 5, 2018 at 1:57 AM, Nathaniel Smith <n...@pobox.com> wrote:
> PEP 3104 says: > > """ > A shorthand form is also permitted, in which nonlocal is prepended to > an assignment or augmented assignment: > > nonlocal x = 3 > > The above has exactly the same meaning as nonlocal x; x = 3. (Guido > supports a similar form of the global statement [24].) > """ > > The PEP metadata says it was approved and implemented in 3.0, yet this > part never seems to have been implemented: > > Python 3.7.0a3+ (heads/master:53f9135667, Dec 29 2017, 19:08:19) > [GCC 7.2.0] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> def f(): > ... x = 1 > ... def g(): > ... nonlocal x = 2 > File "<stdin>", line 4 > nonlocal x = 2 > ^ > SyntaxError: invalid syntax > > Was this just an oversight, or did it get rejected at some point and > no-one remembered to update that PEP? > 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. -- --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