简体   繁体   中英

How to autodoc decorated methods with sphinx?

When i have a decorator with a closure defined like this:

def Decorator(arg):
    class InnerDecorator:
        """Here i use the arg: {arg}"""
        __doc__ = __doc__.format(arg=arg)

        def __init__(self, func):
            self.func = func
            # make arg an instance attribute
            self.arg = arg  

        def __call__(self):
            return self.func()

    return InnerDecorator

Which I use like this:

class MyClass(object):
    @Decorator("ARG")
    def foo(self):
        pass

    @Decorator("Other ARG")
    def bar(self):
        pass

I can see the correct doc-strings for 'foo' and 'bar using the interactive-shell with:

>>> help(MyClass)

My question is: Is there a way to generate autodoc for methods 'foo' and 'bar' with sphinx? I tried,

.. autoclass:: MyClass
    :members:

but that does not work.

Thx so far

This answer helped me to get it work: https://stackoverflow.com/a/15693082/1901330

As answer to my example code i do following:

.. autoclass:: module.MyClass

    .. automethod:: module.MyClass.foo(self)
    .. automethod:: module.MyClass.bar(self)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM