[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/linuxster/python-patterns/master/decorator.py [Back]  [Original]

"""https://docs.python.org/2/library/functools.html#functools.wraps"""
"""https://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python/739665#739665"""

from functools import wraps


def makebold(fn):
    @wraps(fn)
    def wrapped():
        return "" + fn() + ""
    return wrapped


def makeitalic(fn):
    @wraps(fn)
    def wrapped():
        return "" + fn() + ""
    return wrapped


@makebold
@makeitalic
def hello():
    """a decorated hello world"""
    return "hello world"

if __name__ == '__main__':
    print('result:{}   name:{}   doc:{}'.format(hello(), hello.__name__, hello.__doc__))

### OUTPUT ###
# result:hello world   name:hello   doc:a decorated hello world

Web Proxy Viewer  |  New URL  |  Original Page