Skip to content

Instantly share code, notes, and snippets.

@TheBB
Created January 18, 2018 11:53
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 TheBB/19e6364834f944cd5369eda3c7691e56 to your computer and use it in GitHub Desktop.
Save TheBB/19e6364834f944cd5369eda3c7691e56 to your computer and use it in GitHub Desktop.
from functools import wraps
from inspect import getclosurevars
# WITH wraps
def hyphen_decorator(func):
@wraps(func)
def ret():
print('----')
func()
print('----')
return ret
def equals_decorator(func):
@wraps(func)
def ret():
print('====')
func()
print('====')
return ret
@hyphen_decorator
def underlying():
print('beta')
underlying()
underlying = equals_decorator(underlying.__wrapped__)
underlying()
# WITHOUT wraps
def hyphen_decorator(func):
def ret():
print('----')
func()
print('----')
return ret
def equals_decorator(func):
@wraps(func)
def ret():
print('====')
func()
print('====')
return ret
@hyphen_decorator
def underlying():
print('beta')
underlying()
underlying = equals_decorator(getclosurevars(underlying).nonlocals['func'])
underlying()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment