Skip to content

Instantly share code, notes, and snippets.

@hanxiao
Created May 4, 2017 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanxiao/11883419dbb9bf41c03e431b8f55e6bd to your computer and use it in GitHub Desktop.
Save hanxiao/11883419dbb9bf41c03e431b8f55e6bd to your computer and use it in GitHub Desktop.
python decorator wrapper function
def wrapper(v:int = 0):
def f2(f):
def f2_v(*args, **kwargs):
return f(*args, **kwargs) + v
return f2_v
return f2
@wrapper(v=4)
def foo(x:int):
return 3+x
@wrapper(v=4)
def foo2(x:int, y: int):
return 3+x*y
print(foo(1))
print(foo2(1,6))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment