[Python-Dev] nonlocal x = value (original) (raw)
Hrvoje Niksic hrvoje.niksic at avl.com
Fri Dec 24 09:45:56 CET 2010
- Previous message: [Python-Dev] nonlocal x = value
- Next message: [Python-Dev] nonlocal x = value
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 12/23/2010 10:03 PM, Laurens Van Houtven wrote:
On Thu, Dec 23, 2010 at 9:51 PM, Georg Brandl<g.brandl at gmx.net> wrote:
Yes and no -- there may not be an ambiguity to the parser, but still to the human. Except if you disallow the syntax in any case, requiring people to write
nonlocal x = (3, y) which is then again inconsistent with ordinary assignment statements. Right -- but (and hence the confusion) I was arguing for not mixing global/nonlocal with assignment at all, and instead having nonlocal and global only take one or more names. That would (obviously) remove any such ambiguity ;-)
I would like to offer the opposing viewpoint: nonlocal x = value is a useful shortcut because nonlocal is used in closure callbacks where brevity matters. The reason nonlocal is introduced is to change the variable, so it makes sense that the two can be done in the same line of code.
As for global x = value being disallowed, I have been annoyed at times with that, so that sounds like a good argument to change both.
Requiring the parentheses for tuple creation sounds like a good compromise for resolving the ambiguity, consistent with similar limitations of the generator expression syntax.
- Previous message: [Python-Dev] nonlocal x = value
- Next message: [Python-Dev] nonlocal x = value
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]