Created
July 24, 2012 11:56
-
-
Save copitux/3169546 to your computer and use it in GitHub Desktop.
Decorator with args
This file contains hidden or 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
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