kalekundert / autoclasstoc

Sphinx plugin to make easier-to-navigate class documentation.
MIT License
18 stars 7 forks source link

Configuration for omitting sphinx's `:inherited-members:` but using the `include_inherited = True` to permit 'click through' to documented method #14

Closed ryandvmartin closed 2 years ago

ryandvmartin commented 3 years ago

I am working in a project with selective documentation of parent methods/attributes with subclasses that variably override. This package has been invaluable for linking it all together and enabling discoverability. So many thanks in advance!

In our quest for a minimal but perfectly connected doc, we're using include_inherited=True on our custom Sections, but we are purposefully not using the sphinx autodoc option inherited-members to avoid duplicating docstrings and keeping the size down. However, the result of this combination is that the methods listed in Inherited from Parent table are no longer clickable, i.e., we cant navigate VIA the method table link to the documented method on the parent class, even though it exists in our doc.

I am just wondering if there is any way to enable this automatically? I poked around in utils.py:

def make_links(state, attrs):
    """
    Make links to the given class attributes.

    More specifically, the links are made using the :rst:dir:`autosummary`
    directive.
    """
    assert attrs
    return nodes_from_rst(state, [
        '.. autosummary::',
        '',
        *[f'    {x}' for x in attrs],
    ])

and swapping x to atts[x].__qualname__ (for thing that had such attribute) sort of got there...

Another question I had was if it is possible to omit inherited methods that are overridden on the subclass? At present they look to be duplicated (perhaps this is something I need to tweak in our custom sections).

Thanks!

kalekundert commented 3 years ago

Regarding your first question: I noticed this when I was first writing the code, and at the time I couldn't figure out how to get those kinds of links to work. So I normally just do :inherited-members: and live with the fact that everything is duplicated for each class. This is certainly not ideal, though. I can't really remember now what problems I was having, but I'll have to take a look at the attr[x].__qualname__ approach.

Regarding your second question: I don't quite understand what you're asking. Is your goal to omit methods from the superclass documentation if those methods are overridden in any subclasses?

Also, just so you know, it'll probably be a while before I have time to look into these issues myself. If you're interested in making a PR, though, I can review that pretty quickly.

haiiliin commented 2 years ago

I also encountered this issue, so I did some digging in the make_links function and came up with a solution in pull request #22.