a python decorator that applies itself to all methods of a class
  • Python 90.5%
  • Makefile 9.5%
Find a file
2021-04-04 10:37:03 -04:00
decorate_all_methods Cleanup 2021-01-03 21:20:29 -05:00
.gitignore initial 2018-05-09 22:11:05 -04:00
.pylintrc initial 2018-05-09 22:11:05 -04:00
LICENSE Update LICENSE 2021-04-04 10:37:03 -04:00
Makefile add long_description_content_type 2018-06-19 10:01:52 -04:00
README.md Cleanup 2021-01-03 21:20:29 -05:00
setup.py add long_description_content_type 2018-06-19 10:01:52 -04:00

decorate-all-methods

Decorator that applies a decorator to all methods of a class.

Installing

pip install decorate-all-methods

Example Usage

from decorate_all_methods import decorate_all_methods
from tenacity import retry, stop_after_attempt, wait_fixed


@decorate_all_methods(retry(stop=stop_after_attempt(3), wait=wait_fixed(1)), exclude=['__init__'])
class MyClass(object):

    def __init__(self, object):
        """Will not be retried."""
        pass

    def force_error(self):
        """Will be retried 3 times."""
        assert False

    def force_another_error(self):
        """Will also be retried 3 times."""
        assert False

Note: It is not necessary to exclude any methods.

Acknowledgments