Created
June 20, 2012 21:04
-
-
Save trjordan/2962204 to your computer and use it in GitHub Desktop.
Testing signature preserving
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
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