mirror of
https://github.com/davegallant/decorate-all-methods.git
synced 2025-08-06 09:53:38 +00:00
initial
This commit is contained in:
13
decorate_all_methods/__init__.py
Normal file
13
decorate_all_methods/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
"""Iterate through all methods in a class and apply decorator."""
|
||||
|
||||
|
||||
def decorate_all_methods(decorator, exclude=None):
|
||||
if exclude is None:
|
||||
exclude = []
|
||||
|
||||
def decorate(cls):
|
||||
for attr in cls.__dict__:
|
||||
if callable(getattr(cls, attr)) and attr not in exclude:
|
||||
setattr(cls, attr, decorator(getattr(cls, attr)))
|
||||
return cls
|
||||
return decorate
|
Reference in New Issue
Block a user