New answers tagged

5

Rather than using *args you can supply a default positional only argument. def temporary_cache(fn=None, *, ttl=60): ... if fn is not None: return decorator(fn) return decorator If you feel following "flat is better than nested" is best, we can use functools.partial to remove the need to define decorator. def temporary_cache(fn=None, *, ...


Top 50 recent answers are included