Skip to content

Instantly share code, notes, and snippets.

@gjcourt
Created November 23, 2016 02:44
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 gjcourt/988cdbaabd02c67688a62f32af74876b to your computer and use it in GitHub Desktop.
Save gjcourt/988cdbaabd02c67688a62f32af74876b to your computer and use it in GitHub Desktop.
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