Created
January 18, 2018 11:53
-
-
Save TheBB/19e6364834f944cd5369eda3c7691e56 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 | |
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