summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-10 16:09:47 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-08-10 16:24:13 +0900
commitbb09f9215449fcd1524a8c2d3b5cc56009f98a9a (patch)
tree015b9f332a6c8c94a4f1e3ad56d96587aba1f5a9
parentbf26080042fabf6e3aba22cfe05ad8d93bcad3e9 (diff)
downloadsphinx-git-bb09f9215449fcd1524a8c2d3b5cc56009f98a9a.tar.gz
Fix #8091: autodoc: AttributeError is raised on documenting an attribute
Until Python 3.5.2, typing.get_type_hints() raises AttributeError if given object does not have `__code__` attribute. This handles the exception not to crash building documents. Note: The AttributeError was fixed at 3.5.3 refs: https://github.com/python/cpython/commit/991d14fee1805e17647940a2a8cbf4f62f0f09ea
-rw-r--r--CHANGES2
-rw-r--r--sphinx/ext/autodoc/__init__.py6
2 files changed, 8 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index d0e4e6316..1d523f3fd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -40,6 +40,8 @@ Bugs fixed
* #8074: napoleon: Crashes during processing C-ext module
* #8084: autodoc: KeyError is raised on documenting an attribute of the broken
class
+* #8091: autodoc: AttributeError is raised on documenting an attribute on Python
+ 3.5.2
Testing
--------
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py
index 47f6bcb25..f3820f715 100644
--- a/sphinx/ext/autodoc/__init__.py
+++ b/sphinx/ext/autodoc/__init__.py
@@ -1613,6 +1613,9 @@ class DataDocumenter(ModuleLevelDocumenter):
except KeyError:
# a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
annotations = {}
+ except AttributeError:
+ # AttributeError is raised on 3.5.2 (fixed by 3.5.3)
+ annotations = {}
if self.objpath[-1] in annotations:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))
@@ -1986,6 +1989,9 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
except KeyError:
# a broken class found (refs: https://github.com/sphinx-doc/sphinx/issues/8084)
annotations = {}
+ except AttributeError:
+ # AttributeError is raised on 3.5.2 (fixed by 3.5.3)
+ annotations = {}
if self.objpath[-1] in annotations:
objrepr = stringify_typehint(annotations.get(self.objpath[-1]))