diff --git a/CHANGES b/CHANGES index a9abad0671e..726eacf8ea6 100644 --- a/CHANGES +++ b/CHANGES @@ -19,6 +19,8 @@ Bugs fixed * #8164: autodoc: Classes that inherit mocked class are not documented * #8602: autodoc: The ``autodoc-process-docstring`` event is emitted to the non-datadescriptors unexpectedly +* #8616: autodoc: AttributeError is raised on non-class object is passed to + autoclass directive Testing -------- diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 4429a2516b3..b481cf25435 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1662,7 +1662,11 @@ def get_doc(self, encoding: str = None, ignore: int = None) -> List[List[str]]: def add_content(self, more_content: Optional[StringList], no_docstring: bool = False ) -> None: if self.doc_as_attr: - more_content = StringList([_('alias of %s') % restify(self.object)], source='') + try: + more_content = StringList([_('alias of %s') % restify(self.object)], source='') + except AttributeError: + pass # Invalid class object is passed. + super().add_content(more_content, no_docstring=True) else: super().add_content(more_content)