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: 991d14fee1
This commit is contained in:
Takeshi KOMIYA 2020-08-10 16:09:47 +09:00
parent bf26080042
commit bb09f92154
2 changed files with 8 additions and 0 deletions

View File

@ -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
--------

View File

@ -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]))