From 071444e4ac97841653170a6ecf2988d288b11b39 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 10 Aug 2020 16:09:47 +0900 Subject: [PATCH] Fix #8085: 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 --- CHANGES | 2 ++ sphinx/ext/autodoc/__init__.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index d0e4e6316cc..bddfe7f5a98 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 +* #8085: 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 47f6bcb2506..f3820f71552 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1613,6 +1613,9 @@ def add_directive_header(self, sig: str) -> None: 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 @@ def add_directive_header(self, sig: str) -> None: 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]))