On Thu, Sep 29, 2011 at 9:07 PM, Ron Adam <ron3200@gmail.com> wrote:
On Thu, 2011-09-29 at 13:01 -0700, Guido van Rossum wrote:
On Thu, Sep 29, 2011 at 12:03 PM, Eric Snow <ericsnowcurrently@gmail.com> wrote:
The alternative is to leave nonlocal as just a simple statement, but change its behavior when the name is not found inside a containing function scope. Currently that is a syntax error.
For a reason. It would be too easy for a typo to produce the wrong interpretation.
But this is exactly how it works now! The behavior of nonlocal doesn't need to be changed. It already behaves that way with closures. :-)
That isn't what Guido and Eric are talking about here. They're talking about this syntax error:
def f(): ... nonlocal x ... SyntaxError: no binding for nonlocal 'x' found
We had the opportunity in PEP 3104 to make 'nonlocal x' a synonym for 'global x' and chose not to do so. After deliberately passing up that more obvious interpretation, we aren't likely to now decide to use it to denote function state variables. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia