[Python-ideas] Tweaking closures and lexical scoping to include the function being defined

Jim Jewett jimjjewett at gmail.com
Fri Sep 30 21:36:32 CEST 2011

On Fri, Sep 30, 2011 at 5:07 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:

> The reason nonlocal and global declarations need to exist in the first
> place is precisely to override the compiler's default assumption that
> all name bindings in function scope are references to local variables.

And something that I missed the first time -- even if you know a name
shows up in the closure, that doesn't prevent it from being shadowed
locally inside the function.  So the function responsible for
adjusting another function's bytecode (or other function
representation) really does have to know both the contents of the
closure AND which names are being removed from the locals.


More information about the Python-ideas mailing list