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

Nick Coghlan ncoghlan at gmail.com
Mon Sep 26 15:49:32 CEST 2011


On Mon, Sep 26, 2011 at 9:03 AM, Masklinn <masklinn at masklinn.net> wrote:
> An other thing which strikes me as weird is that the proposal is basically the
> creation of private instance attribute on functions. Could you not get the same
> by actually setting an attribute on the function (this can not be used in
> lambdas in any case)?
>
>    def f():
>        print(f.i)
>        f.i += 1
>    f.i = 17

No, because this fails if 'f' is rebound in the outer scope.

> This proposal also does not help with the "reverse argument hack" in lambdas, since
> it's using a statement.

Correct, but the same can be said for 'nonlocal' itself. Besides,
Guido has already nixed the lambda-friendly expression based
suggestions.

Cheers,
Nick.

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



More information about the Python-ideas mailing list