Skip to content

a python decorator that applies itself to all methods of a class

License

Notifications You must be signed in to change notification settings

davegallant/decorate-all-methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

a python decorator that applies itself to all methods of a class

Topics

Resources

License

Stars

Watchers

Forks