Including a decorator in the documentation

For this code:

@my_decorator(arg='abc')
def my_function(x, y):
    """ Return the sum of x and y"""

      

I would like to automatically generate documentation that shows not only the original function (pre-decorator), but the decorator itself. So something like this:

@my_decorator (ar = 'abc')
my_function (x, y)
  return the sum of x and y

Keeping the signature of the original function is not a problem (using a library functools.wraps

or decorator

). But how can I get sphinx

to include the decorator itself?

Given that sphinx autofunction

looks at each function at runtime (after importing the module), the decorator has already been applied, so it seems like the decorator information is already irretrievably lost? Perhaps there is a plugin that can grab decorator information from a static source file and combine it with any sphinx?

I have control over the decorator if that helps.

+3


source to share





All Articles