How can I get Sphinx autosummary to display documents for instance attributes?

All other types (classes, properties, methods, etc.) work fine, but when autosummary gets the attributes of an instance, the error " WARNING: failed to import AClass.a " WARNING: failed to import AClass.a . It is strange that the table is drawn with a link to the documents of the autodoc code below, but the document summary column is empty.

Does anyone have this job or have ideas what might be wrong?

Shows a table with a link, but without documents: enter image description here

Indicates that autodoc is working (the link above would not have been possible without it): enter image description here

I also tried other forms of documentation, such as style #: ... etc. All the same result. Again, everything else in one module works. I view documents in autosummary tables for methods, etc.

Class Example:

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

ReST example:

 .. autosummary:: AClass.a 

I am using Sphinx 1.2.3

+6
source share
1 answer

Unfortunately, autosummary just does not 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 under the autosummary directive for which you want to make a resume, and therefore, in your case, "AClass.a" . However, since instance attributes are not import_by_name , and import_by_name tries to import the name, this fails. I don’t know why the developers did it this way, but we go.

It should be possible to fix this if you have the time and inclination! I discovered a problem to track it.

+2
source

Source: https://habr.com/ru/post/986081/


All Articles