Include specific special-methods in sphinx

前端 未结 5 2089
南旧
南旧 2021-02-12 15:43

I have a bunch of classes which use \"special-methods\":

class Foo(object):
   \"Foo docstring\"

   attr1 = \"Attribute!\" #: first attribute
   attr2 = \"Anoth         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-12 15:59

    I'm currently not 100% thrilled with this solution, so I hope someone can come along an improve it. However, the way I've solved this problem is to do the following:

    .. automodule:: myproject.foomodule
        :members:
        :undoc-members:
        :show-inheritance:
    
        .. autoclass:: myproject.foomodule.Foo
            :exclude-members: attr1,attr2
    
            .. autoattribute:: myproject.foomodule.Foo.attr1 
    
            .. autoattribute:: myproject.foomodule.Foo.attr2 
    
            .. automethod:: myproject.foomodule.Foo.__contains__
    

    Here I actually need to tell autodoc to avoid documenting the class attributes (automatically) and then I need to add them back on explicitly. The reason is because apparently when you explicitly nest commands, the explicit ones come first. If I only explicitly say to add __contains__, then it shows up before the attributes which I didn't like.

提交回复
热议问题