Created
July 24, 2013 13:32
-
-
Save x746e/6070612 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_tracer(func): | |
from functools import wraps | |
@wraps(func) | |
def inner(*args, **kwargs): | |
import ipdb; ipdb.set_trace() | |
return func(*args, **kwargs) | |
return inner | |
def decorate_methods(decorator): | |
''' | |
Decorates all methods of a class with `decorator`. | |
Example usage:: | |
@decorate_methods(some_logging_decorator) | |
class Whatever: | |
... | |
''' | |
import inspect | |
def inner_class_decorator(cls): | |
methods = [(name, member) for (name, member) in inspect.getmembers(cls) if inspect.ismethod(member)] | |
for name, method in methods: | |
setattr(cls, name, decorator(method)) | |
return cls | |
return inner_class_decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment