Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Sphinx autosummary to display the docs for an instance attributes?

All other types (classes, properties, methods, etc) work fine but when autosummary gets to instance attributes it raises "WARNING: failed to import AClass.a" error. The strange thing is the table is drawn with link to the autodoc code docs below but doc summary column is empty.

Does anyone have this working, or have any ideas what might be wrong?

Shows the table with link but no docs: enter image description here

Shows that autodoc is working (the link above wouldn't be possible without it): enter image description here

I've also tried other forms of documentation, such as the #: ... style, etc. All the same result. Again, everything else in the same module works. I DO see docs in autosummary tables for methods etc.

Example class:

class AClass(object):
    def __init__(self):
        self.a = 10
        """
        An example instance attribute

        :type: int
        """

Example ReST:

.. autosummary::

    AClass.a

I'm using Sphinx 1.2.3

like image 674
Rafe Avatar asked Apr 27 '15 17:04

Rafe


1 Answers

Unfortunately, autosummary simply doesn't support this. The bit of code that matters is in sphinx.ext.autosummary.__init__.AutoSummary.get_items which is essentially:

for name in names:

    # <snip>

    try:
        real_name, obj, parent, modname = import_by_name(name, prefixes=prefixes)
    except ImportError:
        self.warn('failed to import %s' % name)
        items.append((name, '', '', name))
        continue

name is the thing under the autosummary directive you want to make a summary for, and so in your case is "AClass.a". However, since instance attributes are not importable, and import_by_name attempts to import the name, this fails. I don't know why the implementers did it like this but there we go.

It should be possible to fix this though, if you have time and inclination! I have opened an issue to track it.

like image 96
daphtdazz Avatar answered Nov 05 '22 21:11

daphtdazz