Created
November 23, 2016 02:44
-
-
Save gjcourt/988cdbaabd02c67688a62f32af74876b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
def my_decorator(x=None): | |
def outer(func): | |
@wraps(func) | |
def inner(self): | |
y = 10 | |
print "x + {0} = {1}".format(y, x + y) | |
func(self) | |
return inner | |
return outer | |
class SomeClass(object): | |
@my_decorator(x=5) | |
def foo(self): | |
print 'Foo' | |
if __name__ == '__main__': | |
instance = SomeClass() | |
assert id(instance.foo) == id(instance.foo) | |
instance.foo() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment