summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-30 23:08:29 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-12-30 23:29:06 +0900
commit0f8debe55863e751ffa2c7ae064a43cf988f1d41 (patch)
treee61828b9e58e9bea20ec54c579e065ac46040ac2
parent3f560cd67239f75840cc7a439ab54d8509c855f6 (diff)
downloadsphinx-git-0f8debe55863e751ffa2c7ae064a43cf988f1d41.tar.gz
Fix #8616: autodoc: AttributeError when non-class is passed 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.
-rw-r--r--CHANGES2
-rw-r--r--sphinx/ext/autodoc/__init__.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index b23778176..0ddf4db76 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
--------
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index a1c642703..7578ebab4 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1662,7 +1662,11 @@ class ClassDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # type:
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)