Change Docking in the Decorator

I use a flask, and some functions have decorators to check for some headers and return some error codes if they are missing.

In these decorators, before I return the decorated function, I do something like

decorated_function.__doc__ += "Returns 400 if the X-Version header is not present."

Is it a python? Is there a better way to achieve this?

I use wraps already from functools.

+4
source share
1 answer
def ModDoc(doc):
    def wrapped(func):
        func.__doc__ = doc
        return func
    return wrapped


@ModDoc("test2")
def test():
    """test"""
    return

print test.__doc__

It will change the tool of everything that it applies. Remember that these changes are purely interactive and will not appear in saved or automatically generated documentation.

+3
source

All Articles