Created
June 25, 2013 04:56
-
-
Save r3/5856023 to your computer and use it in GitHub Desktop.
Review decorators
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 increment_result(func): | |
def wrapper(*args, **kwargs): | |
return func(*args, **kwargs) + 1 | |
return wrapper | |
@increment_result | |
def square_it(number): | |
return number * number | |
def provides_two_args(func): | |
def wrapper(*args, **kwargs): | |
new_args = (1, 2) + args | |
return func(*new_args, **kwargs) | |
return wrapper | |
@provides_two_args | |
def some_func(first, second, third, fourth): | |
return first * second * third * fourth | |
if __name__ == '__main__': | |
assert square_it(2) == 5 | |
assert some_func(3, 4) == 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment