Skip to content

Commit

Permalink
Fix sphinx-doc#8616: autodoc: AttributeError when non-class is passed…
Browse files Browse the repository at this point in the history
… to autoclass

Since 3.4.0, AttributeError is raised when non-class object is passed to
the autoclass directive.  It has built successfully before 3.4.0
release.  So this handles the exception on generating "alias" text.
  • Loading branch information
tk0miya committed Dec 30, 2020
1 parent 3f560cd commit 0f8debe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -17,6 +17,8 @@ Bugs fixed
----------

* #8164: autodoc: Classes that inherit mocked class are not documented
* #8616: autodoc: AttributeError is raised on non-class object is passed to
autoclass directive

Testing
--------
Expand Down
6 changes: 5 additions & 1 deletion sphinx/ext/autodoc/__init__.py
Expand Up @@ -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)
Expand Down

0 comments on commit 0f8debe

Please sign in to comment.