Skip to content

Instantly share code, notes, and snippets.

@r3
Created June 25, 2013 04:56
Show Gist options
  • Save r3/5856023 to your computer and use it in GitHub Desktop.
Save r3/5856023 to your computer and use it in GitHub Desktop.
Review decorators
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