Skip to content

sphinx autosummary: "failed to import Child.model" (inherited instance attribute) #9884

@AntonioCarta

Description

@AntonioCarta

Describe the bug

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 sphinx-build with 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 this a bug? According to #3257 it should be supported. I'm using sphinx-build 4.3.0.

How to Reproduce

MWE to reproduce the error: sphinx-demo.zip
unzip the archive

$ cd docs
$ make html

Expected behavior

inherited instance attributes are documented correctly and without warnings.

Your project

sphinx-demo.zip

Screenshots

No response

OS

WSL 2 (Ubuntu)

Python version

3.9.7

Sphinx version

4.3.0

Sphinx extensions

sphinx.ext.autosummary

Extra tools

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions