[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
jimjjewett at gmail.com
Thu Sep 29 22:24:05 CEST 2011
On Thu, Sep 29, 2011 at 3:03 PM, Eric Snow <ericsnowcurrently at 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.
Until this discussion started, I had not realized that nonlocal was
limited to names from containing *function* scopes; I had thought that
it would end up using the module-level globals if need be.
Having it indicate a scope *closer* than all the scopes where it
already looked but failed to find the name seems wrong.
That said, my intuition may be suspect; outside examples, I have never
used nonlocal, and work fairly hard to avoid global. I don't *like*
boxing up my variables, but it still seems less offensive than a
global statement and the resulting side effects.
More information about the Python-ideas