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

Nick Coghlan ncoghlan at gmail.com
Tue Sep 27 04:23:27 CEST 2011

On Mon, Sep 26, 2011 at 8:03 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
>> My proposed syntax is just a way to explicitly create new entries in
>> that middle category - variables with local visibility and nonlocal
>> lifetime.
> I don't think that's the right way to characterise default
> argument values. While the *values* have nonlocal lifetime,
> the *name* being declared is a parameter, so both its scope
> and lifetime are local. Your proposal would be creating a
> new category of name that doesn't currently exist.

Yes, I did state that for default arguments it referred to the
anonymous values. The only name currently in this category is the
magic __class__ reference in the new super() implementation. Part of
the idea here is to make it so that that name is less of a special

> I don't see how your proposal would do anything to clarify
> the distinction between visibility and lifetime. Currently,
> 'nonlocal' always refers to visibility. Your way, it would
> sometimes mean visibility and sometimes lifetime, with only
> a very obtuse clue as to the difference.

Actually, with my proposal it would always refer to lifetime, and only
sometimes to visibility. The latter case would be implied by the fact
that it isn't initialised inside the current function definition
(currently you *can't* initialise it locally, so the term always
refers to both lifetime *and* visibility).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list