Return value usage

Simon Brunning simon at brunningonline.net
Wed Apr 29 13:14:15 EDT 2009


2009/4/29 Zac Burns <zac256 at gmail.com>:
> I would like to know when my function is called whether or not the
> return value is used. Is this doable in python? If it is, can it ever
> be pythonic?

AFAIK, no, it's not.

> The use case is that I have functions who's side effects and return
> values are cached. I would like to optimize them such that I don't
> have to recall (from a network) the return values if they are not
> used. Obviously it would be possible to add a parameter to the
> function but I would like this optimization to be implemented
> passively because 1. The api is already widely used and 2. I would
> like to keep the complexity of the api to a bare minimum.

Why not return a proxy, and have the proxy do the retrieval of the
needed data if it's used? Delegation is ridiculously easy in Python.

-- 
Cheers,
Simon B.



More information about the Python-list mailing list