Skip to content

Instantly share code, notes, and snippets.

@trjordan
Created June 20, 2012 21:04
Show Gist options
  • Save trjordan/2962204 to your computer and use it in GitHub Desktop.
Save trjordan/2962204 to your computer and use it in GitHub Desktop.
Testing signature preserving
from functools import wraps
from decorator import decorator
def mywrapper1(func, *args, **kwargs):
"""A decorator"""
print 'Wrappedly 1', args, kwargs
return func(*args, **kwargs)
def mywrapper2(*args, **kwargs):
print 'Wrappedly 2', args, kwargs
return myrealfunc(*args, **kwargs)
def myrealfunc(a, b, c=5):
"""Here's a doc string"""
print 'Really', a, b, c
# Do it with decorator
mydecorator = decorator(mywrapper1)
func1 = mydecorator(myrealfunc)
func1(5, 2, c=9)
# Do it with wraps, with duplication!
func2 = wraps(myrealfunc)(mywrapper2)
func2(5, 2, c=9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment