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

Bruce Leban bruce at leapyear.org
Wed Sep 28 02:56:58 CEST 2011


I started to write this mail saying that we could use spellings like
nonlocal.scoped, nonlocal.own, nonlocal.global  and nonlocal.const but then
read the message about declarations in the middle of a function having side
effects at definition time. That seems like a big problem. And it made me
realize it would be weird if (to use one possible bikeshed color):

    own x = y

was not the same as

    own x
    x = y

but I don't see how these can possibly be the same. You need the first case
to do one time initialization and you must be able to change the value as in
the second case or the feature is useless.

I proposed a special decorator-like syntax ($inject) which would pull the
declaration out of the function entirely (putting it at the scope where it
evaluates). There wasn't much discussion other than that it wasn't feasible
with current implementation.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110927/b8b95153/attachment.html>


More information about the Python-ideas mailing list