Skip to content

Instantly share code, notes, and snippets.

@copitux
Created July 24, 2012 11:56
Show Gist options
  • Save copitux/3169546 to your computer and use it in GitHub Desktop.
Save copitux/3169546 to your computer and use it in GitHub Desktop.
Decorator with args
class decorator(object):
def __init__(self, easy_args, with=1, objects=2, decorators=3)
self.easy_args = easy_args
# ...
def __call__(self, func):
@wraps(func) # django.utils.functionals.wraps or functools.update_wrapper (easy debug)
def wrapper(*args, **kwargs):
if self.do_something_with_my_args():
return func(*args, **kwargs)
return what_ever_you_want()
return wrapper
# ...
@decorator('spam', with='foo', objects='bar')
def yeah(oh='yes'):
print oh, 'yeah'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment