Skip to content

Instantly share code, notes, and snippets.

@rasmusto
Last active August 29, 2015 14:07
Show Gist options
  • Save rasmusto/6f4a2a254c2eca92cd11 to your computer and use it in GitHub Desktop.
Save rasmusto/6f4a2a254c2eca92cd11 to your computer and use it in GitHub Desktop.
def decorator(fn):
def f():
return "dec" + fn()
f.decorated=True
f.original_func = fn
return f
def decorator_override(fn):
def f():
if fn.decorated:
return "ovr" + fn.original_func()
else:
return "fresh" + fn()
f.decorated=True
f.original_func=fn
return f
@decorator_override
@decorator
def hello_ovr():
return "hello"
hello_ovr()
# 'ovrhello'
@decorator
def hello():
return "hello"
hello()
# 'dechello'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment