[Python-ideas] fork
Andrew Barnert
abarnert at yahoo.com
Wed Aug 12 05:06:20 CEST 2015
On Aug 11, 2015, at 06:54, Sven R. Kunze <srkunze at mail.de> wrote:
>
> Co-workers proposed using function scopes as the ultimate evaluation scope. That is when a function returns a ResultProxy, it gets evaluated. However, I have absolutely no idea how to do this as I couldn't find any __returned__ hook or something.
I'm not sure I completely understand what you're looking for here.
If you just want a hook that gets called whenever a function returns, just write a decorator that calls the real function then does the hook thing:
def hookify(func):
@wraps
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
do_hook_stuff()
return result
return wrapper
(Or, if you want to hook both raising and returning, use a finally.)
But I'm not sure what good that would do anyway. If you unwrap futures every time they're returned, they're not doing anything useful as futures in the first place; you might as well just return the values directly.
More information about the Python-ideas
mailing list