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

Nick Coghlan ncoghlan at gmail.com
Mon Sep 26 22:17:30 CEST 2011

On Mon, Sep 26, 2011 at 4:01 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 9/26/2011 10:24 AM, Paul Moore wrote:
>> I agree entirely. My point here wasn't to suggest that this needs a
>> new keyword, but rather that the proposal uses an unnatural keyword to
>> avoid needing a new keyword.
>> Your argument that this is a simple extension of the semantics of
>> "nonlocal" is reasonable when viewing nonlocal in terms of lifetimes.
>> My contention is that most people view nonlocal in terms of visibility
>> (and in that view, the two uses of nonlocal are jarringly dissimilar).
> In the template below, the visibility of VAR in _outer is both ephemeral
> (lasting only for one quick call) and non-essential (in that VAR is never
> *used* within _outer.
> Today's default value objects *are* visible non-locally:
>>>> def f(a=3): pass
>>>> f.__defaults__[0]
> 3

Indeed, it could be said that the defining feature of a nonlocal
reference is that it is accessible via the function object, whether
that's through __defaults__, __kwdefaults__ or __closure__.


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

More information about the Python-ideas mailing list