[Python-Dev] nonlocal x = value (original) (raw)

Benjamin Peterson benjamin at python.org
Fri Dec 17 17:08:06 CET 2010


2010/12/17 Stefan Behnel <stefan_ml at behnel.de>:

Hi,

it seems that Py3 doesn't support setting a "nonlocal" value as part of the "nonlocal" command  Python 3.2a4+ (py3k:86480, Nov 16 2010, 16:43:22)  [GCC 4.4.3] on linux2  Type "help", "copyright", "credits" or "license" for more information.  >>> def x():  ...   y = 5  ...   def f():  ...     nonlocal y = 6  File "", line 4  nonlocal y = 6 ^  SyntaxError: invalid syntax even though the PEP clearly describes this feature. http://www.python.org/dev/peps/pep-3104/#proposed-solution Either the PEP or the implementation should be updated. Personally, I think the PEP should be changed as I think that the syntax complicates the grammar more than it's worth. Also, the moratorium applies here, given that Py3.1 does not implement this. Comments?

There's a issue and a patch for this somewhere. I personally don't care; it's not too painful to write two lines.

-- Regards, Benjamin



More information about the Python-Dev mailing list