[Python-Dev] closure semantics

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Fri Oct 24 02:25:52 EDT 2003

> From: Greg Ewing [mailto:greg at cosc.canterbury.ac.nz]
> > It would break any unadorned 'global x' in a nested scope 
> if the name
> > did not exist anywhere.
> > 
> > One option would be to have an "if the name doesn't exist, it it
> > created in module scope".
> What would be wrong with that? It's what I had in mind.

It's complex. Can you explain the complete semantics of 'outer' as simply as:

    global <name> [in <scope>]

    Binds and uses <name> in another scope. If 'in <scope>' is omitted
    then the name is bound and used in the scope of the current module.

My understanding of 'outer' is (and I'm not sure about this):

    outer <name>

    Binds and uses <name> in the innermost scope containing the current
    scope that already has <name> bound. If <name> is not bound in any
    containing scope then it is bound into the scope of the current
    module if <name> is used or bound while executing in the current

    <include warnings about introducing the name into a scope between the
    current scope and the scope where the programmer was expecting the
    name to be bound>

Or something like that.

Tim Delaney

More information about the Python-Dev mailing list