:py:mod:`decorator` =================== .. py:module:: decorator .. autoapi-nested-parse:: Decorators. to enable/disable a function, to memoize a function results... Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: decorator.memoize Functions ~~~~~~~~~ .. autoapisummary:: decorator.enabled decorator.disabled .. py:function:: 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" :param func: function to decorate .. py:function:: 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 :param func: function to decorate .. py:class:: 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. .. py:method:: __call__(*args: Any, **kwargs: Any) -> Any Return the cache value if exist, else call func. .. py:method:: __repr__() -> str Return the function's docstring. .. py:method:: __get__(obj: Any, objtype: Any) -> Any Support instance methods. :param obj: instance object :param objtype: object type