Return value usage

MRAB google at
Wed Apr 29 19:32:22 CEST 2009

Zac Burns wrote:
> 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?
It doesn't sound Pythonic to me.

> 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.
The point of caching is that it lets you retrieve a result cheaply that
was expensive to produce by saving the result in case it's needed again.
If the caching itself is expensive because it requires network access
then, IMHO, that's not proper caching! (You would need a 2-level cache,
ie a small local cache to speed up your a larger network-based cache; a
cache for a cache.)

More information about the Python-list mailing list