Search code examples
python-sphinxautodoc

How to stop Sphinx automethod prefixing method name with class name


When I use Sphinx automethod to document a specific method like so:

.. automethod:: my_module.MyClass.my_method

The resulting docs append the class name to the method name like this:

MyClass.my_method(kwarg1=None, kwarg2=None)

    This is the docstring for my_method...

Is there any way to tell automethod to not prefix the method name with the class name, such that the resulting docs look like this:

my_method(kwarg1=None, kwarg2=None)

    This is the docstring for my_method...

?


Solution

  • In addition to

    add_module_names = False
    

    use

    .. autofunction:: my_module.MyClass.my_method
    

    instead of automodule and the class name is omitted in the generated doc.