[Python-Dev] closure semantics

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Fri Oct 24 00:26:57 EDT 2003


> From: Guido van Rossum [mailto:guido at python.org]
> 
> > We've been assuming all along that the semantics of a
> > plain "global" statement have to remain exactly as they
> > are, but is that strictly necessary?
> > 
> > How much hardship would it cause, really, if "global"
> > were simply redefined to mean "the next scope out where
> > it's bound"?
> 
> Reasonable assumption.  We'd have to do a survey.

It would break any unadorned 'global x' in a nested scope if the name did not exist anywhere.

I'm not saying this would be good form - personally I think anyone who did this would deserve it - but it would definitely break.

One option would be to have an "if the name doesn't exist, it it created in module scope". But all this creates too many exceptions to what would otherwise be a simple rule IMO:

    global <name> [in <scope>]

where <scope> default to the current module.

Tim Delaney



More information about the Python-Dev mailing list