[Python-3000] Draft PEP for outer scopes

Antoine Pitrou solipsis at pitrou.net
Fri Nov 3 23:50:37 CET 2006


Le vendredi 03 novembre 2006 à 16:22 -0600, Ka-Ping Yee a écrit :
> Only x is nonlocal.
> 
>     nonlocal x = y = 0
> 
> is equivalent to
> 
>     nonlocal x; x = y = 0

Perhaps, but the point is that it's non-intuitive from reading.
Just like the old "char * x, y" annoyance in C.

> The point is to make the statement easy to explain.  As Christian
> suggested, prohibiting multiple assignment is an exception: an
> additional rule to remember.

You are just trading one rule for another rule: the rule that only the
leftmost variable in the assignment chain is nonlocal.

In both cases, you have a non-obvious rule to remember. But in one case,
the rule is enforced by syntax, while in the other, it can silently
trigger bugs if not respected.

OTOH if you forbid assignment altogether, there is nothing special to
explain that is not already explained for "global".




More information about the Python-3000 mailing list