Skip to content

Instantly share code, notes, and snippets.

@x746e
Created July 24, 2013 13:32
Show Gist options
  • Save x746e/6070612 to your computer and use it in GitHub Desktop.
Save x746e/6070612 to your computer and use it in GitHub Desktop.
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