Decorators

Decoration Utilities.

misc_utils.decorators.deprecated(info='')[source]

Decorate a deprecated function.

Parameters:info – info to show.

Example

>>> from misc_utils import deprecated
>>>
>>> @deprecated('old_func() is deprecated now, use new_func() instead.')
>>> def old_func():
>>>     pass
>>>
>>> old_func()
>>> # DeprecationWarning: old_func() is deprecated now, use new_func() instead.
misc_utils.decorators.timer(show_args=True, logger=None)[source]

Decorate a function to log how log the function took to execute.

Parameters:logger – logger to write to, print if None.

Example

>>> from misc_utils import timer
>>>
>>> @get_timer(logger)
>>> def test(a, **kwargs):
>>>     for i in range(a):
>>>         time.sleep(1)
>>>
>>> test(3, b=2, c=3)
>>> # [INFO] 2020-01-01 15:30:00 Call ttt(3, b=2, c=3), time: 3s.