[Python-ideas] Allow lambda decorators

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Feb 10 06:13:39 CET 2009

Guido van Rossum wrote:
> You would need rules telling the scope of such a variable:
> with "for new" that is easy, but what if "var foo" is not nested
> inside a loop? Then it would essentially become a no-op. Or would it
> introduce a scope out of the nearest indented block?

In my version of it, 'new' doesn't affect scoping at
all -- the scope of the name that it qualifies is the
same as it would be if the 'new' wasn't there.

It's not necessarily true that it would be a no-op
outside of a loop:

   x = 17
   def f():
     ... # sees x == 17
   new x = 42
   def g():
     ... # sees x == 42

although practical uses for that are probably rather
thin on the ground.

> This quickly
> becomes too hairy to be attractive.

It all seems rather clear and straightforward to
me, once you understand what it does. Some RTFMing
on the part of newcomers would be required, but
nothing worse than what we already have with things
like generators, decorators and with-statements.


More information about the Python-ideas mailing list