[Python-3000] Draft PEP for outer scopes

Ka-Ping Yee python at zesty.ca
Fri Nov 3 23:22:42 CET 2006


On Fri, 3 Nov 2006, Antoine Pitrou wrote:
> Le vendredi 03 novembre 2006 à 15:19 -0600, Ka-Ping Yee a écrit :
> > I suppose that's fine.  Also i guess
> >
> >     nonlocal x = y = 0
>
> That's ambiguous.
> Is only "x" nonlocal, or are both "x" and "y"?

Only x is nonlocal.

    nonlocal x = y = 0

is equivalent to

    nonlocal x; x = y = 0

> What's the point anyway?

The point is to make the statement easy to explain.  As Christian
suggested, prohibiting multiple assignment is an exception: an
additional rule to remember.  I found his argument convincing, and
realized that prohibiting chained assignment is another exception.

Consistently allowing these forms of assignment makes the
description simple:

    If you see 'nonlocal' in front of an assignment, it means
    the same as a 'nonlocal' declaration (read from the beginning
    up to the assignment operator) followed by the assignment.

This tells you both what the statement means and how to tell
whether your syntax is valid.  No exceptions to memorize.


-- ?!ng


More information about the Python-3000 mailing list