[Python-ideas] Tweaking closures and lexical scoping to include the function being defined
Arnaud Delobelle
arnodel at gmail.com
Wed Sep 28 21:38:27 CEST 2011
On 28 September 2011 19:08, Eric Snow <ericsnowcurrently at gmail.com> wrote:
[...]
> The Def-time Value Approach
> ------------------------------------
>
> For def-time values, the values would have to be stored in a function
> attribute similar to __defaults__ and __kwdefaults__. Let's call it
> __spam__. A keyword (not "nonlocal" <wink>) in the function body
> would indicate that the name should be initialized with each call to
> the appropriate value in __spam__. Then we would have a (builtin?)
> decorator factory that would update values in __spam__:
>
> #<example>
>
> def init_deftime(**kwargs):
> def decorator(f):
> for name in kwargs:
> index = figure_out_index(f, name)
> f.__spam__[index] = kwargs[name]
> #functools.update_spam(f, name, kwargs[name])
> return f
> return decorator
>
> @init_deftime(x=5):
> def f():
> some_keyword x
> print(x)
Mmh. This looks exactly like one I posted earlier on:
http://mail.python.org/pipermail/python-ideas/2011-September/011892.html
--
Arnaud
More information about the Python-ideas
mailing list