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

Guido van Rossum guido at python.org
Tue Sep 27 19:10:35 CEST 2011

On Tue, Sep 27, 2011 at 3:14 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Sep 27, 2011 at 3:36 AM, Ron Adam <ron3200 at gmail.com> wrote:
>> Don't give up just yet,  I think you may just need an out of the box
>> view point to see it from a different angle...
> As far as I can see from the discussion so far, proposing 'nonlocal'
> for this use case *is* the out of the box viewpoint seeing it from a
> different angle ;)

Which reminds me of a Calvin and Hobbes cartoon. Calvin has a bad
report card and says "You know how Einstein's grades were bad? Well
mine are even *worse*!"

IOW, out of the box thinking doesn't automatically lead to the right
conclusion. :-)

You can argue that nonlocal is about lifetime instead of visibility
until you're blue in the face, but I still disagree. It is first and
foremost about visibility. Lifetime is secondary. Note how a nonlocal
variable may actually have a lifetime longer than that of the function
using it that declares it as nonlocal -- that function object may be
deleted from the containing scope, but the variable of course still
exists in the containing scope.

--Guido van Rossum (python.org/~guido)

More information about the Python-ideas mailing list