[Python-ideas] Before and after the colon in funciton defs.

Steven D'Aprano steve at pearwood.info
Fri Sep 23 01:51:26 CEST 2011


Paul Moore wrote:

> a = 10
> def foo():
>     a = 20
>     b = static a
> 
> What should that mean? Clearly b isn't 20, as a wasn't set to 20 at
> function define time. But b = 10 (on the assumption that "static a"
> takes the value of a at define time) will confusing to users, I would
> suggest. Not allowed might be best, but I suspect it could be hard to
> implement.

With decorator syntax, the scoping rules are obvious and straightforward:

a = 10
@inject(b=a)
def foo():
     a = 20
     return b+a




-- 
Steven



More information about the Python-ideas mailing list