[Python-Dev] Whatever happened to 'nonlocal x = y'? (original) (raw)

Nathaniel Smith njs at pobox.com
Fri Jan 5 04:57:02 EST 2018


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 "", 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?

-n

-- Nathaniel J. Smith -- https://vorpus.org



More information about the Python-Dev mailing list