4

I'm having trouble with sphinx and autosummary. Apparently, sphinx is unable to document inherited instance attributes. For some reason, the resulting error is an import error.

python code:

class Base:
    """Base class."""

    def __init__(self, **kwargs):
        """Init."""
        self.model = None
        """An attribute."""


class Child(Base):
    """Child class."""

    def __init__(self, **kwargs):
        """Init."""
        super().__init__()
        pass

rst documentation file:

.. autosummary::
    :toctree: generated

    mylib.Base
    mylib.Child

when I run make html I get the following error:

.../new_docs/generated/mylib.Child.rst:24: WARNING: autosummary: failed to import Child.model

Notice that everything else is imported correctly, so this is not a path issue.

Is it possible to resolve this problem? I'm using sphinx-build 4.3.0.

mzjn
  • 48,958
  • 13
  • 128
  • 248
Muller20
  • 71
  • 1
  • 6
  • 2
    I can reproduce this. There is a problem with inherited instance attributes. A related issue about instance attributes was closed this year: https://github.com/sphinx-doc/sphinx/issues/3257. – mzjn Nov 21 '21 at 17:29
  • Thanks @mzjn. Do you think that this is a sphinx bug and I should open an issue on github? Your linked issue suggests that my example should work without warnings. – Muller20 Nov 22 '21 at 11:00
  • Bug report: https://github.com/sphinx-doc/sphinx/issues/9884 – mzjn May 02 '22 at 16:04

0 Answers0