decorator
¶
Decorators.
to enable/disable a function, to memoize a function results…
Module Contents¶
Classes¶
Memoize function return values. |
Functions¶
|
no-op. Do not change function behaviour. |
|
Disable the provided function, and does nothing. |
- decorator.enabled(func: collections.abc.Callable) collections.abc.Callable ¶
no-op. Do not change function behaviour.
If you write the following code:
@enabled def foo(): print("I'm foo")
Then calling
foo()
will return “I’m foo”- Parameters:
func – function to decorate
- decorator.disabled(func: collections.abc.Callable) collections.abc.Callable ¶
Disable the provided function, and does nothing.
If you write the following code:
@disabled def foo(): print("I'm foo")
Then calling
foo()
will return None- Parameters:
func – function to decorate
- class decorator.memoize(func: collections.abc.Callable)¶
Memoize function return values.
Avoid repeating the calculation of results for previously-processed inputs.
If you write the following code:
import random @memoize def long_computation(r): del r return random.random()
Then you will have:
long_computation(42) == long_computation(42)
Calling the same function twice with the same paramaters returns the same result.
Calling the function with the special keyword argument reset_cache=True force a call to the decorated function, skipping the cache.
No keyword argument can be passed to the decorated function.
- __call__(*args: Any, **kwargs: Any) Any ¶
Return the cache value if exist, else call func.
- __repr__() str ¶
Return the function’s docstring.
- __get__(obj: Any, objtype: Any) Any ¶
Support instance methods.