-
-
Save anonymous/54b26d120ffb8a2412e2 to your computer and use it in GitHub Desktop.
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 mydec(c, f): | |
def r_dec(function): | |
def wrapper(*args, **kwargs): | |
print "## PRE-RUN CODE HERE ##" | |
getattr(c(), f)(*args[1:], **kwargs) | |
print "## POST-RUN CODE HERE ##" | |
return wrapper | |
return r_dec | |
class B: | |
def func1(self, a, b, c): | |
print "B::func1 %s %s %s" % (a, b, c) | |
class A: | |
@mydec(B, "func1") | |
def func1(self, a, b, c): | |
print "A::func1 %s %s %s" % (a, b, c) | |
print "Calling original B.func1 (unwrapped)" | |
y = B() | |
y.func1(1, 2, 3) | |
print "---" | |
print "Calling A.func1 wrapping B.func1" | |
x = A() | |
x.func1(1, 2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment