This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jhylton
Recipients akuchling, amaury.forgeotdarc, benjamin.peterson, georg.brandl, jhylton
Date 2010-02-24.16:24:53
SpamBayes Score 2.4868996e-14
Marked as misclassified No
Message-id <e8bf7a531002240824i7718b3e7m1973125577064022@mail.gmail.com>
In-reply-to <1267003222.86.0.168467727851.issue4199@psf.upfronthosting.co.za>
Content
I guess there's some question about whether the syntax in the PEP was
considered carefully when it was approved.  If so, I'm not sure that
we want to re-open the discussion.  On the other hand, it's been a
long time since the PEP was approved and we do have a moratorium on
language changes, so it doesn't hurt to slow things down.

I'd argue that the intent of the PEP is pretty clear.  You can take
any assignment statement where the LHS doesn't have subscripts, put a
nonlocal or global in front of it, and it means that all those
assignments are to global/nonlocal variables.

Jeremy

On Wed, Feb 24, 2010 at 4:20 AM, Georg Brandl <report@bugs.python.org> wrote:
>
> Georg Brandl <georg@python.org> added the comment:
>
>> I also notice that the Grammar in the PEP is more complicated:
>> nonlocal_stmt ::=
>>     "nonlocal" identifier ("," identifier)*
>>                ["=" (target_list "=")+ expression_list]
>>   | "nonlocal" identifier augop expression_list
>>
>> The Grammar in the patch is:
>> +global_stmt: 'global' NAME (',' NAME)* [','] ['=' testlist]
>> +nonlocal_stmt: 'nonlocal' NAME (',' NAME)* [','] ['=' testlist]
>>
>> It appears that the PEP is trying to support:
>>
>> nonlocal x = y = z = 1
>> nonlocal a, b = c, d = 1
>
> It also tries to support augmented assignment; however I'm not sure what the semantics of that should be.
>
> Further, there is an ambiguity if too much freedom is allowed: what about
>
>   global x = 1, y
>
> Is it declaring a global "x" and assigning a tuple, or declaring a global "x" and a global "y"?
>
>> If we're going to support the PEP as written, I think we need to
>> modify Global() and Nonlocal() to look exactly like Assign(), but add
>> an extra check to verify that all of the expressions in the targets
>> are Name, List, or Tuple.  You'd probably want to check this at the
>> time you are generating the AST, so that you're not stuck with some
>> extra state in the compiler traversal about whether you are generating
>> code for a Global() or an Assign().
>
> I would not support List or Tuple as targets.  Same basic problem as
> above, and I don't see a use case.
>
> I see two possibilities for the actual syntax:
>
> 1) global *either* supports multiple identifiers, *or* one identifier
> and an assignment.
>
> 2) global always supports multiple identifiers, each with an optional
> assignment; tuples need parentheses.
>
> In both cases, I would keep it simple and not allow multiple targets or
> augmented assignment.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue4199>
> _______________________________________
>
History
Date User Action Args
2010-02-24 16:24:55jhyltonsetrecipients: + jhylton, akuchling, georg.brandl, amaury.forgeotdarc, benjamin.peterson
2010-02-24 16:24:54jhyltonlinkissue4199 messages
2010-02-24 16:24:53jhyltoncreate